|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
我是菜岛。做一资料输入模块,见附件。窗体有关联combobox、textbox,当二分类选择“信贷融资”时,提示“下标越界”,其他正常。2种方式,都这样。请大侠指导。谢谢!
方法1:
Private Sub ComboBox3_Enter()
Dim i As Long '声明数据类型
Dim y As String
ComboBox3.Clear
y = ComboBox1.Value
For i = 3 To Sheets(y).[b2].End(xlDown).Row
target = Sheets(y).Cells(i, 2)
If target = TextBox5.Text Then
ComboBox3.AddItem Sheets(y).Cells(i, 3)
Dim k As Integer
Dim j As Integer
For k = 0 To ComboBox3.ListCount - 2
For j = (k + 1) To ComboBox3.ListCount - 1
If ComboBox3.List(k) = ComboBox3.List(j) Then ComboBox3.RemoveItem (j)
Next
Next
End If
If target <> TextBox5.Text Then
ComboBox3.Value = ""
Exit Sub
End If
Next
End Sub
方法2:
Private Sub TextBox5_Change()
Dim x As String
Dim y As String
Dim arr, brr(), crr(), i&, m&
y = ComboBox1.Value
x = TextBox5.Text
If x <> "" Then
arr = Sheets(y).Range("b3:d" & Sheets(y).[b65536].End(xlUp).Row)
For i = 1 To UBound(arr)
If InStr(arr(i, 1), x) > 0 Then
m = m + 1
ReDim Preserve brr(1 To m)
ReDim Preserve crr(1 To m)
brr(m) = arr(i, 2)
crr(m) = arr(i, 3)
ComboBox3.AddItem brr(m)
Dim k As Integer
Dim l As Integer
For k = 0 To ComboBox3.ListCount - 2
For l = (k + 1) To ComboBox3.ListCount - 1
If ComboBox3.List(k) = ComboBox3.List(l) Then ComboBox3.RemoveItem (l)
Next
Next
ComboBox6.AddItem crr(m)
End If
Next
End If
End Sub
|
|