Filter specific column in listbox

Xlacs

Board Regular
Joined
Mar 31, 2021
Messages
105
Office Version
  1. 2016
Platform
  1. Windows
Hi Good People,

Hoping someone could actually me on this problem. So basically, I have a textbox and a Listbox thats filter via textbox value. However, I wanted to show only a specific column of my listbox.

Below code filters my listbox.
My search starts in a2, if textbox value match the value in column A of my Sheet, then it shows all the items in listbox based on textbox value.

What I wanted to achieve is to show only lets say column B and column G only..

Is that possible? Thank you


VBA Code:
Private Sub TextBox1_Change()
Dim a, i As Long, ii As Long, n As Long, temp As String
If Len(Me.TextBox1.Value) Then
    temp = UCase(Me.TextBox1.Value)
    With Sheets("sheet1")
        a = .Range("a2", .Range("a" & Rows.Count).End(xlUp)) _
        .Resize(, 2).Value
    End With
    a = Application.Transpose(a)
    For i = 1 To UBound(a, 2)
        If UCase(a(1, i)) Like temp & "*" Or _
            UCase(a(2, i)) Like temp & "*" Then
            n = n + 1
            For ii = 1 To UBound(a, 1)
                a(ii, n) = a(ii, i)
            Next
        End If
    Next
    If n > 0 Then
        ReDim Preserve a(1 To UBound(a, 1), 1 To n)
        Me.ListBox1.Column = a
    End If
End If
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
It maybe requires modification but the idea is:
VBA Code:
Dim strWidths As String
For y = 0 To UBound(a, 1)
  Select Case y
    Case 1, 5
      strWidths = strWidths + ";"  
    Case Else
      strWidths = strWidths + "0cm;"
    End Select
Next y
ListBox1.ColumnWidths = (strWidths)
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Filter specific column in listbox - OzGrid Free Excel/VBA Help Forum
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,822
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top