我正在尝试用填充表单中的特定数据填充报表表格,这样做时,它可以很好地处理带有一个表格的表格,但是如果代码是正确的话我可以使用更多的表格,我认为有要做的事情,使它做得很好。因此,通过更正代码或提供其他方式,我们将非常感谢您的帮助。提前谢谢
Private Sub Search_Click() ' firstly I do search
Dim cRow As String
On Error Resume Next
cRow = Me.txtSearch.Value
'find the name of the employee written on the search box in column B
Set FindRow = Sheets("Current Payroll").Range("B:B").Find
(what:=cRow,LookIn:=xlValues)
If Not FindRow Is Nothing Then '<-- successful find
'add the values to the userform
Me.txtname.Value = FindRow.Value
Me.txtposition.Value = FindRow.Offset(0, 1).Text
Me.Locationtxt.Value = FindRow.Offset(0, 4).Text
End If
End Sub
Private Sub UpdateAdavance_Click()
Dim the_Sheet1 As Worksheet
Dim the_Sheet2 As Worksheet
Dim cRow As Integer
Dim table_list_object As ListObject
Dim table_object_row As ListRow
Dim x As Integer
On Error Resume Next
'find the row with the data on the search box
Set FindRow = Sheets("Current Payroll").Range("B7:B").
Find(what:=cRow, LookIn:=xlValues)
'add the values to deduction report table number 3
Set the_Sheet1 = Sheets("Deduction Report")
Set table_list_object = the_Sheet1.ListObjects(3)
Set table_object_row = table_list_object.ListRows.Add
table_object_row.Range(1, 1).Value = Me.txtname.Text
table_object_row.Range(1, 2).Value = Me.txtposition.Text
table_object_row.Range(1, 3).Value = Me.Locationtxt.Text
table_object_row.Range(1, 4).Value = Me.txtadvance.Value
table_object_row.Range(1, 5).Value = Format(Me.Datetxt.Value, "mmmm dd, yy")
table_object_row.Range(1, 6).Value = Me.AdvanceReason.Text
'add the values to current month report table number5
Set the_Sheet2 = Sheets("current month report ")
Set table_list_object = the_Sheet2.ListObjects(5)
Set table_object_row = table_list_object.ListRows.Add
table_object_row.Range(1, 1).Value = Me.txtname.Text
table_object_row.Range(1, 2).Value = Me.txtposition.Text
table_object_row.Range(1, 3).Value = Me.Locationtxt.Text
table_object_row.Range(1, 4).Value = Me.txtadvance.Value
table_object_row.Range(1, 5).Value = Format(Me.Datetxt.Value, "mmmm dd, yy")
table_object_row.Range(1, 6).Value = Me.AdvanceReason.Text
End Sub