|
出个难题。
心中有个想法,不知可否实现
Dim rng As Range
Set rng = Sheet1.Range("A2:C" & rw) ' 关键字所在的区域
Dim dic As Object
Set dic = CreateObject("scripting.dictionary")
ListView1.ListItems.Clear ' 清除所有内容
For i = 2 To rw
For ii = 1 To 3
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 ' 因为是一行多列查找,所以只要有一个单元格符合要求,要需要换行,否则listitem数据重复
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) = Format(Sheet1.Cells(i, 4), "#,##0")
total = total + Sheet1.Cells(i, 4).Value
End If
End If
Next ii
Next i
Label2.Caption = "共找到 " & ListView1.ListItems.Count & " 条记录"
Label3.Caption = "总计: " & Format(total, "#,##0")
Set dic = Nothing
查找是从电子表中重复查找,能不能当窗口SHOW时,就装载了数据,当查找时从 ListView1中查询,或是在RECORD中用字典再筛选出结果。 |
|