如何在电子表格的正确列中传输用户窗体文本框值
How to transfer userform textbox value in correct column in spreadsheet
我正在尝试创建一个用户表单,操作员将从工作订单中扫描他们的“操作”(“OperationBox”文本框),然后将他们的“员工 ID #”(“IDbox”文本框)输入到正确的列中在传播sheet。输入的值也将显示在列表框中。
sheet 的名称是“数据库”;用户表单的名称是“ScanForm”。
我不确定如何进行此检查,然后用 ID# 填充展开sheet 单元格。任何帮助都会很棒。
谢谢
ScanForm
Database spreadsheet
Sub Submit()
'Transfer data from the form to the database
Dim sh As Worksheet
Dim iRow As Long
Set sh = ThisWorkbook.Sheets("Database")
'Utilizing iRow variable to store the next blank row number to transfer the data from Form to Database.
iRow = [Counta(Database!A:A) + 1]
With sh
.Cells(iRow, 1) = ScanForm.JobBox.Value
If .Cells(b, 1) = OperationBox.Value Then
.Cells(iRow, 2) = ScanForm.IDbox.Value
End If
If OperationBox.Value = .Cells("C1").Value Then
.Cells(iRow, 3) = ScanForm.IDbox.Value
End If
If OperationBox.Value = .Cells("D1").Value Then
.Cells(iRow, 4) = ScanForm.IDbox.Value
End If
.Cells(iRow, 5) = ScanForm.PartBox.Value
.Cells(iRow, 6) = ScanForm.QtyBox.Value
.Cells(iRow, 7) = [Text(Now(), "DD-MM-YY HH:MM")]
End With
结束子
遍历列 headers 以与 OperationBox 匹配。
Option Explicit
Sub Submit1()
'Transfer data from the form to the database
Dim sh As Worksheet, iRow As Long, c As Long
Dim rng As Range
Set sh = ThisWorkbook.Sheets("Database")
'Utilizing iRow variable to store the next blank row number
'to transfer the data from Form to Database.
iRow = sh.Cells(Rows.Count, 1).End(xlUp).Row + 1
' extend list box
Set rng = Range(Scanform.ListBox1.RowSource)
Scanform.ListBox1.RowSource = rng.Resize(iRow).Address
With sh
.Cells(iRow, 1) = Scanform.JobBox.Value
For c = 2 To 4
If .Cells(1, c) = Scanform.OperationBox.Value Then
.Cells(iRow, c) = Scanform.IDbox.Value
Exit For
End If
Next
.Cells(iRow, 5) = Scanform.PartBox.Value
.Cells(iRow, 6) = Scanform.QtyBox.Value
.Cells(iRow, 7) = [Text(Now(), "DD-MM-YY HH:MM")]
End With
End Sub
我正在尝试创建一个用户表单,操作员将从工作订单中扫描他们的“操作”(“OperationBox”文本框),然后将他们的“员工 ID #”(“IDbox”文本框)输入到正确的列中在传播sheet。输入的值也将显示在列表框中。 sheet 的名称是“数据库”;用户表单的名称是“ScanForm”。
我不确定如何进行此检查,然后用 ID# 填充展开sheet 单元格。任何帮助都会很棒。
谢谢
ScanForm Database spreadsheet
Sub Submit()
'Transfer data from the form to the database
Dim sh As Worksheet
Dim iRow As Long
Set sh = ThisWorkbook.Sheets("Database")
'Utilizing iRow variable to store the next blank row number to transfer the data from Form to Database.
iRow = [Counta(Database!A:A) + 1]
With sh
.Cells(iRow, 1) = ScanForm.JobBox.Value
If .Cells(b, 1) = OperationBox.Value Then
.Cells(iRow, 2) = ScanForm.IDbox.Value
End If
If OperationBox.Value = .Cells("C1").Value Then
.Cells(iRow, 3) = ScanForm.IDbox.Value
End If
If OperationBox.Value = .Cells("D1").Value Then
.Cells(iRow, 4) = ScanForm.IDbox.Value
End If
.Cells(iRow, 5) = ScanForm.PartBox.Value
.Cells(iRow, 6) = ScanForm.QtyBox.Value
.Cells(iRow, 7) = [Text(Now(), "DD-MM-YY HH:MM")]
End With
结束子
遍历列 headers 以与 OperationBox 匹配。
Option Explicit
Sub Submit1()
'Transfer data from the form to the database
Dim sh As Worksheet, iRow As Long, c As Long
Dim rng As Range
Set sh = ThisWorkbook.Sheets("Database")
'Utilizing iRow variable to store the next blank row number
'to transfer the data from Form to Database.
iRow = sh.Cells(Rows.Count, 1).End(xlUp).Row + 1
' extend list box
Set rng = Range(Scanform.ListBox1.RowSource)
Scanform.ListBox1.RowSource = rng.Resize(iRow).Address
With sh
.Cells(iRow, 1) = Scanform.JobBox.Value
For c = 2 To 4
If .Cells(1, c) = Scanform.OperationBox.Value Then
.Cells(iRow, c) = Scanform.IDbox.Value
Exit For
End If
Next
.Cells(iRow, 5) = Scanform.PartBox.Value
.Cells(iRow, 6) = Scanform.QtyBox.Value
.Cells(iRow, 7) = [Text(Now(), "DD-MM-YY HH:MM")]
End With
End Sub