Sorting Multiple Columns in a Listbox

chipsworld

Board Regular
Joined
May 23, 2019
Messages
164
Office Version
  1. 365
All...I found the below on this site, and it works beautifully, but...

Was wondering if there is anyway to mod the code to filter two separate columns? i.e. First by Date, then by Name (Columns 15 and then 2)

Any help would be greatly appreciated. This is a hard code sort...no checks, combo boxes, etc....

Trying to not re-invent the wheel if possible... I have this embedded in the sub to load the listbox, and it works perfectly. Just wanted to see how complicated it would be to expand it capabilities.

VBA Code:
Dim vData As Variant
Dim vTemp As Variant
Dim i As Long
Dim j As Long
Dim k As Long

Dim SortByCol As Long

SortByCol = 15 ' sort by date created

 With Me.lstboxchoice
        vData = .List
        For i = LBound(vData, 1) To UBound(vData, 1) - 1
            For j = i + 1 To UBound(vData, 1)
                If vData(i, SortByCol) < vData(j, SortByCol) Then
                    For k = LBound(vData, 2) To UBound(vData, 2)
                        vTemp = vData(i, k)
                        vData(i, k) = vData(j, k)
                        vData(j, k) = vTemp
                    Next k
                End If
            Next j
        Next i
        
        .List = vData
    
    End With
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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