|
楼主 |
发表于 2011-8-27 17:36
|
显示全部楼层
对了。是这样。以下是我在textbox中模糊查询
但要求查询对象:
Private Sub TextBox1_Change()
Dim what As String: what = TextBox1.Value
Dim rw As String: rw = Sheet1.Range("A65536").End(xlUp).Row
Dim total As String
total = 0
If TextBox1.Value = "" Then
'
ListView1.ListItems.Clear
With Sheet1
For I = 2 To rw
Set ITM = ListView1.ListItems.Add()
ITM.Text = .Cells(I, 1)
ITM.SubItems(1) = .Cells(I, 2)
ITM.SubItems(2) = .Cells(I, 3)
ITM.SubItems(3) = .Cells(I, 4)
ITM.SubItems(4) = .Cells(I, 5)
ITM.SubItems(5) = .Cells(I, 6)
total = total + .Cells(I, 6).Value
Next I
End With
TextBox1.SetFocus
Exit Sub
Else
Dim rng As Range
Set rng = Sheet1.Range("A2:F" & rw)
Dim dic As Object
Set dic = CreateObject("scripting.dictionary")
ListView1.ListItems.Clear '
For I = 2 To rw
For ii = 1 To 2
Dim tmp As Range
Set tmp = Sheet1.Cells(I, ii).Find(what, lookat:=xlPart, MatchCase:=False) '
If Not tmp Is Nothing Then
If Not dic.exists(tmp.Row) Then '
dic.Add tmp.Row, ""
Set ITM = ListView1.ListItems.Add()
ITM.Text = Sheet1.Cells(I, 1)
ITM.SubItems(1) = Sheet1.Cells(I, 2)
ITM.SubItems(2) = Sheet1.Cells(I, 3)
ITM.SubItems(3) = Sheet1.Cells(I, 4)
ITM.SubItems(4) = Sheet1.Cells(I, 5)
ITM.SubItems(5) = Sheet1.Cells(I, 6)
total = total + Sheet1.Cells(I, 6).Value
End If
End If
Next ii
Next I
Set dic = Nothing
End If
End Sub |
|