My Data has 4 columns with the following headings: Heading 1,Heading 2,Heading 3 and Heading 4.
I have created a Listbox using the below code. In the userform i have 2 Option Buttons which indicates 2 columns. I want to sort my listbox based on the selection. Example: if I select the 'serial number' option box, it should filter based on the first column value (Heading 1) and if I choose 'job', it should filter based on the third column value (Heading 3).
Can anybody help me to find a code for that?
Please see below the code for the listbox.
Private Sub UserForm_Initialize()
With ListBox1
.ColumnCount = 4
.ColumnWidths = "130;30;30;130"
End With
LstRow = Cells(Rows.Count, 1).End(xlUp).Row
For a = 0 To LstRow - 2
b = a + 2
ListBox1.AddItem
ListBox1.list(a, 0) = Cells(b, 4)
ListBox1.list(a, 1) = Cells(b, 1)
ListBox1.list(a, 2) = Cells(b, 3)
ListBox1.list(a, 3) = Cells(b, 2)
Next a
End Sub