|
楼主 |
发表于 2014-4-25 19:42
|
显示全部楼层
再修改一下:
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, ":")
nCol = [A65536].End(xlUp).Row
ReDim brr(1 To nCol, 1 To UBound(arr) + 1)
For i = 1 To nCol
For j = 1 To UBound(arr) + 1
brr(i, j) = Cells(i, Val(arr(j - 1))).Value
Next j
Next i
Dim crr
Dim cc, m, n
crr = [{"序号",40;"物料类别",60;"物料编码",70;"物料名称",150;"材质",50;"规格型号",80;"颜色",50}] '预定义各列的宽度
For m = 1 To UBound(brr, 2)
For n = 1 To UBound(crr)
If brr(1, m) = crr(n, 1) Then
cc = cc & crr(n, 2) & ","
End If
Next
Next
With Me.ListBox1
.Clear
.ColumnCount = UBound(brr)
.ColumnWidths = Left(cc, Len(cc) - 1)
.ListIndex = -1
.List = brr
End With
End Sub
|
|