請教大大:
程式語法如下,如果ListBox2想要有篩選之後呈現
例如第四欄位為姓名(TextBox4) ,like TextBox4 均list 於 ListBox2
應如何寫?
Sub showlastdatas()
Dim str1 As String
wb3.Activate
str1 = Left(TextBox31, 5) & CommandButton4.Caption
With Sheets(str1)
row1 = .Cells(65536, 4).End(xlUp).Row
If row1 < 2 Then Exit Sub
Dim mystr As String
With Application.Names.Add("Tmp2", .Range(.Cells(2, 1), .Cells(row1, 24)))
mystr = .RefersTo
.Delete
End With
ListBox2.RowSource = ""
With ListBox2
.ColumnCount = 24
.ColumnWidths = "78pt;60pt;80pt;70pt;40pt;105pt;90pt;115pt;90pt;90pt;90pt;70pt;70pt;80pt;90pt;90pt;90pt;120pt;120pt;120pt;80pt;120pt;80pt;60pt"
.RowSource = mystr
.ColumnHeads = True
.ListIndex = ListBox2.ListCount - 1
End With
End With
End Sub
感謝指導作者: yangjie 時間: 2021-1-14 22:42
本帖最後由 yangjie 於 2021-1-14 22:46 編輯
我想可能諸位大大不懂我的困擾所在
Dim mystr As String
With Application.Names.Add("Tmp2", .Range(.Cells(2, 1), .Cells(row1, 24)))
'Tmp2是全部資料,而我要的是含部分條件之資料
'Tmp2在Range(.Cells(2, 1), .Cells(row1, 24))之中篩選出.cell(ii,4)=Textbox4的每一列
'是否應先篩選到另一個sheets然後再mystr = .RefersTo
mystr = .RefersTo
.Delete
End With
ListBox2.RowSource = ""
With ListBox2
.ColumnCount = 24
.ColumnWidths = "78pt;60pt;80pt;70pt;..........."
.RowSource = mystr
.ColumnHeads = True
.ListIndex = ListBox2.ListCount - 1
End With
End With
敬請指導 不勝感激作者: 准提部林 時間: 2021-1-16 11:50