|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
给个查询的方式,更方便Private Sub TextBox1_Change()
Dim 托盘数 As Double
Dim 总重量 As Double
Dim list As ListItem
Dim li As ListSubItem
Dim arr
Dim i As Long
ListView1.ListItems.Clear
arr = Sheets("sheet1").UsedRange
For i = 2 To UBound(arr)
If arr(i, 1) Like "*" & TextBox1.Text & "*" Then
Set list = ListView1.ListItems.Add(Text:=arr(i, 1))
list.SubItems(1) = arr(i, 2)
list.SubItems(2) = arr(i, 3)
list.SubItems(3) = arr(i, 4)
list.SubItems(4) = arr(i, 5)
list.SubItems(5) = arr(i, 6)
list.SubItems(6) = arr(i, 7)
托盘数 = 托盘数 + arr(i, 4)
总重量 = 总重量 + arr(i, 5)
End If
Next i
Set list = ListView1.ListItems.Add(Text:="合计")
list.ForeColor = RGB(255, 0, 0)
list.Bold = True
list.SubItems(1) = ""
list.SubItems(2) = ""
Set li = list.ListSubItems.Add
li.Text = 托盘数
li.ForeColor = RGB(255, 0, 0)
li.Bold = True
Set li = list.ListSubItems.Add
li.Text = 总重量
li.ForeColor = RGB(255, 0, 0)
li.Bold = True
End Sub |
|