• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Search in the second visible column of the LIstBox

S P P

Member
How to change this VBA that searches in the first visible column of the ListBox.

Search in the second visible column of the ListBox.

>>> You've noted many times <<<
>>> use code - tags <<<

Code:
Private Sub T_40_Change()
Dim StrText As String
    StrText = LCase(T_40.Text)
    With LB_00
 For i = 0 To .ListCount - 1
    If LCase(Left(.List(i), Len(StrText))) = StrText Then Exit For
Next i
    If i = .ListCount Then .ListIndex = -1
    If i <> .ListCount Then .ListIndex = i
End With
End Sub
 
Last edited by a moderator:
What is the column number in your sheet where you want to search?
How is de listbox populated?
 
Try this
Code:
Private Sub T_40_Change()
On Error Resume Next
lijst = [Table1].value
        arg = 0
        For i = 1 To UBound(lijst)
            If InStr(1, lijst(i, 2), T_40, vbTextCompare) > 0 Then
                arg = arg + 1
            End If
        Next i
        ReDim nwlijst(arg - 1, 40)
        arg = 0
        For i = 1 To UBound(lijst)
            If InStr(1, lijst(i, 2), T_40, vbTextCompare) > 0 Then
                For k = 1 To 40
                    nwlijst(arg, k - 1) = lijst(i, k)
                Next k
                arg = arg + 1
            End If
        Next
        LB_00.List = nwlijst
End Sub
 
Did not work

Completing the Listbox

>>> You've noted many times <<<
>>> use code - tags <<<
Code:
Private Sub UserForm_Activate()
Dim ws As Worksheet
Dim rng As Range
Set ws = Sheets(1)
Set rng = ws.ListObjects(1).DataBodyRange
LB_00.RowSource = "'" & ws.Name & "'!" & rng.Address
LB_00.ColumnHeads = True
 
Last edited by a moderator:
I never use rowsource to populate a listbox but list then it wil work but without a small example?
 
I'm trying a VBA with a CamboBox filled with table titles

This way I can search in all columns

According to the selected title
 
Back
Top