|
Private Sub CommandButton2_Click() '''查询
Dim arr()
Dim rng As Range
ReDim arr(1 To ListView1.ListItems.Count, 1 To ListView1.ColumnHeaders.Count)
If ListView1.ListItems.Count < 1 Then MsgBox "对不起!没有你想要导出的数据": Exit Sub
Set rng = ActiveSheet.Rows(1)
zd = textbox102.Text
lj = CreateObject("wscript.shell").specialfolders.Item("desktop") & ("\")
For i = 1 To ListView1.ListItems.Count
If ListView1.ListItems(i).SubItems(3) = zd Then
m = m + 1
arr(m, 1) = ListView1.ListItems(i)
For j = 1 To ListView1.ColumnHeaders.Count - 1
arr(m, j + 1) = ListView1.ListItems(i).SubItems(j) '
Next j
End If
Next i
If m = "" Then Exit Sub
With ListView1
.ListItems.Clear '清除内容数据
For i = 1 To m '在新数组的行内循环
If Trim(arr(i, 1)) <> "" Then
Set Itm = .ListItems.Add
Itm.Text = arr(i, 1)
For j = 2 To UBound(arr, 2)
Itm.SubItems(j - 1) = arr(i, j)
Next j
End If
Next i
End With
MsgBox "查询到" & m & "行数据!", 0, "提醒"
End Sub
|
|