VBA编程.如何将数据从用户形式传输到特定的行和列到表



我目前正在研究替代出席监控系统作为主动性。目前,我设计了我的用户形式,看起来像以下一个:时间邮票用户形式

它是这样的工作:

  1. 员工将选择他/她将使用的时间戳类型:时间,超时,第一休假开始,第一休假结束,第二休假开始或第二休假结束。

    <</p>
  2. 然后,人员编号将在人事条形码字段中输入。

目前,我有此代码:

Private Sub CancelButton_Click()
    Unload Me
End Sub
Private Sub ClearButton_Click()
    Call UserForm_Initialize
End Sub
Private Sub OKButton_Click()
    Dim emptyRow As Long
    'Make Sheet1 active
    Sheet1.Activate
    'Determine emptyRow
    emptyRow = WorksheetFunction.CountA(Range("B:B")) + 1
    'Transfer information
    If TimeOptionButton1.Value = True Then
        Cells(emptyRow, 5).Value = "Yes"
    End If
    If TimeOptionButton2.Value = True Then
        Cells(emptyRow, 7).Value = "Yes"
    End If
    If BreakOptionButton1.Value = True Then
        Cells(emptyRow, 9).Value = "Yes"
    End If
    If BreakOptionButton2.Value = True Then
        Cells(emptyRow, 11).Value = "Yes"
    End If
    If BreakOptionButton3.Value = True Then
        Cells(emptyRow, 14).Value = "Yes"
    End If
    If BreakOptionButton4.Value = True Then
        Cells(emptyRow, 16).Value = "Yes"
    End If
    Cells(emptyRow, 2).Value = BarcodeTextBox.Value
End Sub
Private Sub UserForm_Initialize()
'Set Time In as default
    TimeOptionButton1.Value = True
    'Empty BarcodeTextBox
    BarcodeTextBox.Value = ""
End Sub

我并不是VBA编码方面的专家,我刚刚在线搜索了代码。上面的代码确定将输入数据的下一个空行。填写用户形式后,在表中产生的结果如下:结果

您可以看到,在多行上输入了1名员工的时间戳。

但是,我想要的只有1行会专用于一个员工号码,以便他/她的时间戳全部为1行,而不是多行。我希望有人可以帮助我。我想到有一个代码,如果已经在表格上搜索输入的人员条形码,则将在同一行中输入时间邮票。我希望它可以在1行上,以便可以轻松地配制公式,例如计算越来越多的人数。

非常感谢您的撒玛利亚人!:)

对您的代码更改,请尝试更改行

`emptyRow = WorksheetFunction.CountA(Range("B:B")) + 1`

进入这个:

Dim rFound as Range: Set rFound = Range("B:B").Find(BarcodeTextBox.Value, , , xlWhole)
If rFound Is Nothing then
    emptyRow = Range("B" & Rows.Count).End(xlUp).Row + 1
Else
    emptyRow = rFound.Row
End If

最新更新