Need a custom VBA function - Is List Sorted?

Sthrncali

Board Regular
Joined
Apr 1, 2011
Messages
226
I am looking for a custom VBA Function that will check if a list is sorted Ascending or Descending, and will flip the sort orientation based on the result...

So basically if a list is either A - Sorted Descending or B - Unsorted, the function would return FALSE, otherwise it would return TRUE.

From there I can specify how to resort the list.

I thought I could load the list range into an array, then test array(i) to see if it matches the first row in my list, and repeat that process for maybe 10 or 15 rows, to determine if the list is sorted...

Does that sound plausible?

I am just trying to place a button at the top of the column where when the user clicks it the first time it will sort ascending, then after that it will toggle between ascending and descending.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I found a formula that seems like it might work for this purpose =Code() however it doesn't appear to be available from VBA...

Application.WorksheetFunction.Code() doesn't work..

Any ideas?
 
Upvote 0
The VBA equivalent is ASC()

Sub test()
MsgBox Asc("A")
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,704
Members
452,938
Latest member
babeneker

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