PDA

View Full Version : Sort Userform ListBox



vmjamshad
10-30-2017, 04:29 AM
Dear All,

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 user from i have 2 Option Buttons which indicates 2 columns. I want to sort my list box based on the selection. Example: if the 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 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

macropod
10-30-2017, 08:51 PM
Cross-posted at: https://www.mrexcel.com/forum/excel-questions/1029241-sort-userform-listbox.html
Please read VBA Express' policy on Cross-Posting in item 3 of the rules: http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3

vmjamshad
10-30-2017, 11:16 PM
Cross-posted at: https://www.mrexcel.com/forum/excel-questions/1029241-sort-userform-listbox.html
Please read VBA Express' policy on Cross-Posting in item 3 of the rules: http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3

OK..will follow