VBA与查找单元格的问题

所以我一直在为员工制定一个假期日历,而且我遇到了一个我似乎找不到解决scheme的问题。

我有两个button被分配到一个VBA脚本,我有一个假期条目的问题。 我似乎无法从用户表单input中select特定的单元格来输出数据。 代码如下所示:

Private Sub ComboBox2_Change() End Sub Private Sub CommandButton1_Click() Dim emptyRow As Long 'Make Sheet1 active 'Holiday Calendar.Activate 'Determine emptyRow 'ActiveCell = (A5) 'emptyRow = WorksheetFunction.CountA(Range("Employees")) + 1 NextRow = 5 Do Until Sheets("Holiday Calendar").Cells(NextRow, 4) = Username.Value NextRow = NextRow + 1 Loop 'Transfer information Cells(NextRow, 6).Value = TypeOfLeave.Value Cells(NextRow, 5).Value = (EndDate.Value) + 1 - (StartDate.Value) End Sub Private Sub CommandButton2_Click() Call UserForm_Initialize End Sub Private Sub CommandButton3_Click() Unload Me End Sub Private Sub DTPicker1_CallbackKeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer, ByVal CallbackField As String, CallbackDate As Date) End Sub Private Sub UserForm_Click() End Sub Private Sub UserForm_Initialize() 'Empty UsernameTextBox Username.Value = "" 'Empty TypeOfLeave ComboBox TypeOfLeave.Clear 'Fill TypeOfLeaveComboBox With TypeOfLeave .AddItem "AL - Anual Leave" .AddItem "WFH - Work From Home" '.AddItem "" End With 'Set Focus on UsernameTextBox Username.SetFocus End Sub 

这是整个用户表单的代码的样子。

现在我需要帮助的是,当用户inputs他们假期的开始和结束date时,它将在spreadsheet查找username ,并相应地在date中放置“ AL-Anual Leave ”和“ WFH – 在家工作 ”用户提供了。

所以我需要的是一段代码,它将从用户表单中findspreadsheet的date,并input值“ Al ”或“ WFH

如果有任何不清楚的地方,请让我知道和不适当的解释。 我试图包括图片,但没有足够的声誉,所以这是很难的。 如果需要更好地解释,我可以通过电子邮件发送图像。

基于我们上面的意见,我想如果你可以先给这个代码段试一下,让我知道如果它仍然不工作。

 Private Sub ComboBox2_Change() End Sub Private Sub CommandButton1_Click() Dim emptyRow As Long 'Make Sheet1 active 'Holiday Calendar.Activate 'Determine emptyRow 'ActiveCell = (A5) 'emptyRow = WorksheetFunction.CountA(Range("Employees")) + 1 Username.Value = UsernameTextBox.Value NextRow = 5 Do Until Sheets("Holiday Calendar").Cells(NextRow, 4) = Username.Value NextRow = NextRow + 1 Loop 'Transfer information Cells(NextRow, 6).Value = TypeOfLeave.Value Cells(NextRow, 5).Value = (EndDate.Value) + 1 - (StartDate.Value) End Sub Private Sub CommandButton2_Click() Call UserForm_Initialize End Sub Private Sub CommandButton3_Click() Unload Me End Sub Private Sub DTPicker1_CallbackKeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer, ByVal CallbackField As String, CallbackDate As Date) End Sub Private Sub UserForm_Click() End Sub Private Sub UserForm_Initialize() 'Empty UsernameTextBox Username.Value = "" 'Empty TypeOfLeave ComboBox TypeOfLeave.Clear 'Fill TypeOfLeaveComboBox With TypeOfLeave .AddItem "AL - Anual Leave" .AddItem "WFH - Work From Home" '.AddItem "" End With 'Set Focus on UsernameTextBox Username.SetFocus End Sub