我在电子表格中有一个日期列表,这些日期旁边是与该日期对应的详细信息,我有一个组合框,可以查找列表中的所有日期,但是当我从下拉列表中选择特定日期时希望它在表单上的文本框中显示该行中的相应数据,到目前为止我有:
Private Sub ComboBox1_Change()
Dim rw As Long, cl As Range
staffName = TextBox8.Value
rw = WorksheetFunction.Match(Me.ComboBox1.Value, Worksheets(staffName).Range("A16:A18"), 0)
TextBox1 = Worksheets(staffName).Range("A" & rw).Offset(0, 1)
TextBox2 = Worksheets(staffName).Range("A" & rw).Offset(0, 2)
TextBox3 = Worksheets(staffName).Range("A" & rw).Offset(0, 3)
TextBox4 = Worksheets(staffName).Range("A" & rw).Offset(0, 4)
End Sub
它没有错误,但它没有任何想法?
答案 0 :(得分:0)
如何将Match更改为vba Find
函数,如下所示:
Private Sub ComboBox1_Change()
Dim cl As Range, wks As Worksheet
staffname = TextBox8.Value
Set wks = Sheets(staffname)
Set cl = wks.Range("A16:A18").Find(Me.ComboBox1.Value, lookat:=xlWhole)
With Me
.TextBox1.Value = cl.Offset(, 1)
.TextBox2.Value = cl.Offset(, 2)
.TextBox3.Value = cl.Offset(, 3)
.TextBox4.Value = cl.Offset(, 4)
End With
End Sub