当我在 ComboBox1 中选择一个值时,ComboBox2 会自动填充指定范围内的数据。在 ComboBox2 中选择一个值时,相应的值将被放置在一个 TextBox 中。看来,当我在 ComboBox 值中只有数字时,代码将不起作用。如果该值由字母或数字和字母组成,则一切正常。我尝试了该范围内单元格的不同格式,但没有成功。在互联网上寻找答案是有问题的,因为我不知道搜索的关键字。
到目前为止,这是我的代码:
Private Sub ComboBox1_Change()
Dim index1 As Integer
Dim cLoc1 As Range
Dim index2 As Integer
Dim cLoc2 As Range
Dim ws As Worksheet
Set ws = Worksheets("Formlists")
index1 = ComboBox1.ListIndex
'index2 = ComboBox2.ListIndex
ComboBox2.Clear
ComboBox3.Clear
Select Case index1
Case Is = 0
With ComboBox2
For Each cLoc1 In ws.Range("Codelist1")
With Me.ComboBox2
.AddItem cLoc1.Value
End With
Next cLoc1
End With
Case Is = 1
With ComboBox2
For Each cLoc1 In ws.Range("Codelist2")
With Me.ComboBox2
.AddItem cLoc1.Value
End With
Next cLoc1
End With
End Select
End Sub
Private Sub combobox2_change()
Dim index2 As Integer
Dim ws As Worksheet
Set ws = Worksheets("Formlists")
index2 = ComboBox1.ListIndex
Select Case index2
Case Is = 0
With TextBox4
For i = 1 To 10
If ws.Cells(i + 1, Columns(90).Column).Value = ComboBox2.Value Then
TextBox4.Value = ws.Cells(i + 1, Columns(91).Column).Value
Else
'do nothing
End If
Next i
End With
Case Is = 1
With TextBox4
For i = 1 To 10
If ws.Cells(i + 1, Columns(92).Column).Value = ComboBox2.Value Then
TextBox4.Value = ws.Cells(i + 1, Columns(93).Column).Value
Else
'do nothing
End If
Next i
End With
End Select
End Sub
有没有办法让代码/组合框接受任何输入格式?
提前致谢
抢