我有以下问题:
一家公司正在测试复合样品。在一个表中添加了样本的信息。在第二个表(“测试结果”)上,首先只显示SampleID编号。样品被送到实验室,4个月后收到测试结果。秘书现在必须更新“测试结果”表。因此,她转到了sampleID和所有相关数据字段中的Userform Types。她点击了更新表。
程序现在会自动在测试结果中搜索样本ID,并使用数据编辑该行的所有列。
我的代码如下所示:
Dim lstObj As ListObject
Dim objNewRow As ListRow
Dim i As Integer
Dim ID As ListObject
Dim tbl As ListObject
Dim tRows As Long
Dim tCols As Long
Set Obj = Worksheets("Tests Results").ListObjects("Test_results")
'count rows
Set tbl = Worksheets("Tests Results").ListObjects("Test_results")
With tbl.DataBodyRange
tRows = .Rows.Count
End With
For i = 1 To tRows
If Obj = Me.sampleID.Value Then
Set objNewRow = lstObj.ListRows.Change(AlwaysInsert:=True)
With Obj
.ListColumns("Test Lab").DataBodyRange(x) = Me.ComboBox_LAB.Value
.ListColumns("Flammability Type ").DataBodyRange(x) = Me.ComboBoxFlamm.Value
.ListColumns("Avg-Smoke Density Pass Value (Ds)").DataBodyRange(x) = Me.ComboBoxSDpass.Value
.ListColumns("Maximum Smoke Density Pass Value_Flaming_ (DS)").DataBodyRange(x) = Me.ComboBoxMAXSD.Value
.ListColumns("Smoke Density Mode").DataBodyRange(x) = Me.ComboBoxSmoke.Value
end with
End If
End For