|
发表于 2016-7-11 09:17
|
显示全部楼层
本楼为最佳答案
- Private Sub CommandButton1_Click()
- Dim d, i%
- Set d = CreateObject("Scripting.Dictionary")
- ListView1.ListItems.Clear '清除listview1中的内容
- With Sheets("记录")
- For j = 2 To .[A65536].End(xlUp).Row
- If Not d.Exists(.Cells(j, 1).Value) Then
- d.Add .Cells(j, 1).Value, .Cells(j, 5).Value
- End If
- Next
- End With
-
- With Sheets("库存")
- For i = 2 To .[C65536].End(xlUp).Row
- If InStr(1, .Cells(i, 3).Value, TextBox1.Text, vbTextCompare) Then
- Set itm = ListView1.ListItems.Add() '为listview1控件里面的行添加内容
- itm.Text = .Cells(i, 2) '为行标赋值
- itm.SubItems(1) = .Cells(i, 3)
- itm.SubItems(2) = .Cells(i, 4)
- itm.SubItems(3) = .Cells(i, 5)
- itm.SubItems(4) = .Cells(i, 6)
- itm.SubItems(5) = d(.Cells(i, 3).Value)
- End If
- Next i
- If ListView1.ListItems.Count = 0 Then MsgBox "未查询到相关记录!", 64, "结果"
- End With
- End Sub
复制代码 |
|