|
- Private Sub ComboBox1_Change()
- If ComboBox1 = "" Then
- TextBox1 = ""
- TextBox2 = ""
- End If
- Dim i As Integer, X As Integer, Y As Integer
- Dim dsD As Object
- ListView1.ListItems.Clear
- With Sheet3
- X = .Range("a65536").End(xlUp).Row
- arrData = .Range("a2:e" & X)
- End With
- For i = 1 To UBound(arrData)
- If arrData(i, 1) Like "*" & ComboBox1.Value Then
- With ListView1.ListItems.Add(, , arrData(i, 1))
- For Y = 2 To UBound(arrData, 2)
- .SubItems(Y - 1) = arrData(i, Y)
- Next Y
- End With
- End If
- Next i
- Dim min%, max%, cj%
- If Len(TextBox1.Text) = 0 Or Len(TextBox2.Text) = 0 Then Exit Sub
- If Not (IsNumeric(TextBox1.Text) And IsNumeric(TextBox2.Text)) Then Exit Sub
- min = Val(TextBox1.Text)
- max = Val(TextBox2.Text)
- If min > max Then Exit Sub
- Call ListFilter(min, max)
- End Sub
- Private Sub ListFilter(ByVal min As Integer, ByVal max As Integer)
- Dim cj%, i&
- With ListView1
- For i = .ListItems.Count To 1 Step -1
- cj = Val(.ListItems(i).SubItems(4))
- If Not (cj >= min And cj <= max) Then
- .ListItems.Remove (i)
- End If
- Next
- End With
- End Sub
- Private Sub CommandButton1_Click()
- Dim min%, max%, cj%
- If Len(TextBox1.Text) = 0 Or Len(TextBox2.Text) = 0 Then
- MsgBox "请输入最小值和最大值"
- Exit Sub
- End If
- If Not (IsNumeric(TextBox1.Text) And IsNumeric(TextBox2.Text)) Then
- MsgBox "请输入数值"
- Exit Sub
- End If
- min = Val(TextBox1.Text)
- max = Val(TextBox2.Text)
- If min > max Then MsgBox "最小值不能大于最大值": Exit Sub
- Call ListFilter(min, max)
- End Sub
复制代码 增加自动筛选功能。
其实在添加进LISTVIEW的时候就可以做判断。 |
|