|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub SetListBox()
Dim i As Long, j As Long
ListBox1.Clear
w = ""
With ListBox1
.ColumnCount = 7 '设置列数
For j = 1 To 7
w = w & Sheet1.Cells(1, j).Width & ";"
Next
w = Left(w, Len(w) - 1)
.ColumnWidths = w
.ColumnHeads = False '是否显示列标题
a = Sheet1.Range("A" & Rows.Count).End(xlUp).Row
If a < 2 Then a = 2
ar = Sheet1.Range("a1:g" & a)
ReDim my(1 To a, 1 To 7)
For j = 1 To 7
my(1, j) = ar(1, j)
Next j
b = 1
For i = 2 To a
m = 0
For j = 1 To 7
If ar(i, j) Like "*" & UCase(TextBox1) & "*" Then
m = m + 1
End If
Next j
If m > 0 Then
b = b + 1
For j = 1 To 7
my(b, j) = ar(i, j)
Next j
End If
Next i
ListBox1.List = my
End With
End Sub
|
|