0

我在电子表格中有一个日期列表,这些日期旁边是与该日期相对应的详细信息,我有一个组合框,可以找到列表中的所有日期,但是当我从下拉列表中选择特定日期时,我希望它在表单的文本框中显示该行中的相应数据,到目前为止我有:

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

它没有错误,但它没有任何想法?

4

1 回答 1

0

如何将 Match 更改为 vbaFind函数,如下所示:

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
于 2012-10-23T13:27:55.247 回答