发现单元格

时间:2015-08-05 15:37:26

标签: excel vba excel-vba input

因此,我一直在为员工制作假日日历,而且我遇到了一个我似乎无法找到解决方案的问题。

我有两个分配给VBA脚本的按钮,我对它有一个假日条目问题。我似乎无法从用户表单输入中选择特定单元格来输出数据。代码如下所示:

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假期的开始和结束日期时,它会在username内查找spreadsheet并放置" AL-Anual Leave "和" WFH - 在家工作"因此,在用户提供的日期。

所以我需要的是一段代码,它会在用户表单的spreadsheet内找到日期,input的值为" Al &# 34;或" WFH "

如果其中任何一项不清楚,请告诉我并解释不清楚。我尝试过包括图片,但没有足够的声誉,所以它更难。如果需要更好的解释,我可以通过电子邮件发送图像。

1 个答案:

答案 0 :(得分:0)

根据我们上面的评论,我想先试试这段代码,然后告诉我它是否仍无法正常工作。

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