Bài viết phổ biến của tác giả
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在研究一种替代出勤监控系统作为一项举措。目前,我设计的用户表单如下所示: Time Stamp Userform
它的工作原理如下:
员工将选择他/她将使用的时间戳类型:开始时间、超时、第一次休息开始、第一次休息结束、第二次休息开始或第二次休息结束。
然后在人员条码字段中输入人员编号。
目前,我有以下代码:
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编码方面的专家,我只是在网上搜索了代码。上面的代码确定将输入数据的下一个空行。填写用户表单后,工作表中的结果如下所示: Results
如您所见,1 名员工的时间戳被输入到多行中。
但是,我想要的只是 1 行专用于一个员工编号,以便他/她的所有时间戳都在 1 行中,而不是在多行中。我希望有人能在这方面帮助我。我想到有一个代码,其中输入的人员条形码将被搜索,如果它已经在工作表上,如果是,则时间戳将被输入在同一行上。我希望它位于 1 行,以便可以轻松制定公式,例如计算超限和人数。
提前非常感谢您的好心人! :)
1 Câu trả lời
对代码进行最小程度的更改,尝试更改行
`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
关于VBA 编程。如何将数据从用户窗体传输到工作表的特定行和列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41176069/
Tôi là một lập trình viên xuất sắc, rất giỏi!