|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
VBA万岁 发表于 2014-4-25 14:01
是这样的吗?
代码改进如下:
Private Sub TextBox1_Change()
Dim i%, j%, c As Long, s$, arr, brr
For i = 1 To Cells(1, Cells.Columns.Count).End(xlToLeft).Column - 1
If InStr(TextBox1.Text, Cells(1, i).Value) > 0 Then s = s & ":" & i
Next i
If s <> "" Then
s = Right(s, Len(s) - 1)
Else
For i = 1 To Cells(1, Cells.Columns.Count).End(xlToLeft).Column - 1
If InStr(Cells(1, i).Value, TextBox1.Text) > 0 Then s = i: Exit For
Next i
End If
arr = Split(s, ":")
ReDim brr(1 To ListBox1.ListCount, 1 To UBound(arr) + 1)
For i = 1 To ListBox1.ListCount
For j = 1 To UBound(arr) + 1
brr(i, j) = Cells(i, Val(arr(j - 1))).Value
Next j
Next i
ListBox1.Clear
ListBox1.List = brr
End Sub
Private Sub UserForm_Initialize()
Dim Myr&, arr
nRow = Sheet1.[A65536].End(xlUp).Row
arr = ActiveSheet.UsedRange
With Me.ListBox1
.Clear
.ColumnCount = 7
'.BoundColumn = 7
.ColumnWidths = "40,60,70,150,50,80,50"
'.ColumnHeads = True
.ListIndex = -1
'.RowSource = Sheet1.Range("A1:G" & nRow).Address(External:=True)
.List = arr
End With
End Sub
|
评分
-
1
查看全部评分
-
|