Dermot

VBA: Enhance and speed up random numbers and sorting, using spill functions

Dermot

Board Regular
Joined
Aug 11, 2006
Messages
199
Office Version
  1. 365
Platform
  1. Windows
Dermot submitted a new Excel article:

VBA: Enhance and speed up random numbers and sorting, using spill functions - VBA: Enhance and speed up random numbers and sorting, using spill functions

Sorting Arrays
VBA does not have a built in sort function, which requires having your own sorting code. But now, the Excel Sort function can be used in VBA, and based on my testing, it is faster than my quicksort function.
Note that the array must be 2D, eg (1000,1) or (500,3)

For example if you have an array A, you can sort it into an array B like this
VBA Code:
B = Application.WorksheetFunction.Sort(A)
you can include a sort column and sort direction if needed, just as in...

Read more about this Excel article...
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Thank you for this. It hadn't yet occurred to me to use the SORT function in VBA, so this is extremely useful. Your point about how the array must be 2D jumped out at me. Is this because the SORT function expects a range as an argument?

I encountered the same issue when I tried using the UNIQUE function in VBA, and while it just wouldn't work with a simple 1D array (e.g., MyArray(1 to 10), passing it a range as a argument (a list in Range("A1:A10")) would work fine. Obviously, Range("A1:A10") converts into a 2D array, so I'm guessing that's also what's happening with SORT?
 
Thank you for this. It hadn't yet occurred to me to use the SORT function in VBA, so this is extremely useful. Your point about how the array must be 2D jumped out at me. Is this because the SORT function expects a range as an argument?

I encountered the same issue when I tried using the UNIQUE function in VBA, and while it just wouldn't work with a simple 1D array (e.g., MyArray(1 to 10), passing it a range as a argument (a list in Range("A1:A10")) would work fine. Obviously, Range("A1:A10") converts into a 2D array, so I'm guessing that's also what's happening with SORT?
I would guess that's the reason. The developers are having to juggle the introduction of spill functions with the risk of changing existing functions to be better behaved, so I think we'll be living with oddities like this for some time.
 

Forum statistics

Threads
1,216,503
Messages
6,131,022
Members
449,616
Latest member
PsychoCube

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