我已经尝试使用此代码在 VBA 中使用列表框从 excel 中查找特定数据,它填充了 sheet3 范围(E7)中的名称列表,然后每次我单击其上的项目/名称时,程序应该从 sheet3 中找到名称并显示将该行上的数据放入我的用户表单中相应的文本框中。但这不能正常工作。谢谢。
Private Sub ListBox1_Click()
Dim isRow As Long
If Me.ListBox1.ListIndex > -1 Then
isRow = Me.ListBox1.ListIndex + 1
End If
Me.Label1 = Cells(sRow, 5)
Me.txt_Mon_in.Text = Cells(sRow,6)
End Sub
从 Sheet3 填充数据。
Private Sub Userform_Initialize()
Dim vCol As Variant
Dim Lrow As Long
Lrow = Sheets("Sheet3").UsedRange.Rows(Sheets("Sheet3").UsedRange.Rows.Count).Row
vCol = Sheets("Sheet3").Range("E7:E" & Lrow).Value
Me.ListBox1.List = vCol
End Sub