sách gpt4 ai đã đi

Lập trình VBA. Làm thế nào tôi có thể chuyển dữ liệu từ UserForm sang các hàng và cột cụ thể của một Bảng tính?

In lại 作者:行者123 更新时间:2023-12-02 19:21:35 29 4
mua khóa gpt4 Nike

我目前正在研究一种替代出勤监控系统作为一项举措。目前,我设计的用户表单如下所示: Time Stamp Userform

它的工作原理如下:

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

  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编码方面的专家,我只是在网上搜索了代码。上面的代码确定将输入数据的下一个空行。填写用户表单后,工作表中的结果如下所示: 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/

29 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com