Sort a VBA array by multiple columns

JohnLynam1

New Member
Joined
Jan 16, 2025
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am trying to sort an array with multiple columns (called OutputArray1), first by its first column values and then by its second column values and then by its 5th column values and store the new array as outputArray2 . I am aware of the function below, but I can't seem to extend it to sort by multiple columns. Is there a way to do this?

OutputArray2 = WorksheetFunction.Sort(OutputArray1, 1, 1, False).

Thanks for any help. Cheers
 
Try this:

VBA Code:
OutputArray2 = WorksheetFunction.Sort(OutputArray1, Array(1, 2, 5), Array(1, 1, 1), False)

Note: you can put it back into the same array variable if you don't want to create a 2nd variable ie have OutputArray1 = ...
 
Last edited:
Upvote 1
Solution
Alex, that works perfectly. Thank you so much. It would never have occurred to me to try that syntax.
 
Upvote 0
You're welcome. Glad I could help.

PS: In the worsheet the 2 arrays would just be in curly brackets {}
 
Last edited:
Upvote 0

Forum statistics

Threads
1,226,771
Messages
6,192,926
Members
453,767
Latest member
922aloose

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