|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 瓶砸 于 2019-8-23 17:01 编辑
求助.rar
(108.62 KB, 下载次数: 11)
具体想达到的就是想在窗口中实现类似于图中自动筛选一样的效果。代码在userform1里。
自己写的代码如下。
- Private Sub TextBox1_Change()
- Dim arr()
- arr = Sheet1.Range("a2:c" & Sheet1.Range("b65536").End(xlUp).Row)
- Me.ListBox1.Clear
- If InStr(Me.TextBox1.Value, Space(1)) = 0 Then
- sb = Trim(Me.TextBox1.Value)
- Else
- t = Me.TextBox1.Value
- t = Split(t, Space(1))
- End If
- If InStr(Me.TextBox1.Value, Space(1)) = 0 Then
- For i = 1 To UBound(arr)
- If InStr(arr(i, 1), Me.TextBox1.Value) > 0 Or _
- InStr(arr(i, 2), Me.TextBox1.Value) > 0 Or _
- InStr(arr(i, 3), Me.TextBox1.Value) > 0 Then
- Me.ListBox1.AddItem
- Me.ListBox1.List(Me.ListBox1.ListCount - 1, 0) = arr(i, 1)
- Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = arr(i, 2)
- Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = arr(i, 3)
- End If
- Next
- Else
- For i = 1 To UBound(arr)
- For j = 0 To UBound(t)
- sb = Trim(t(j))
- If InStr(arr(i, 1), sb) = 0 Or _
- InStr(arr(i, 2), sb) = 0 Or _
- InStr(arr(i, 3), sb) = 0 Then Exit For
- Next
-
- If j = UBound(t) + 1 Then
- Me.ListBox1.AddItem
- Me.ListBox1.List(Me.ListBox1.ListCount - 1, 0) = arr(i, 1)
- Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = arr(i, 2)
- Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = arr(i, 3)
- End If
- Next
- End If
-
- If Me.ListBox1.ListCount > 0 Then
- Me.ListBox1.Visible = True
- Else
- Me.ListBox1.Visible = False
- End If
-
- End Sub
复制代码 具体问题出在哪里琢磨了一下午没看出来,还望各位老师不吝赐教。
|
|