Conditional sort - ascending if sorted descending

Magriza

Well-known Member
Joined
Nov 16, 2005
Messages
509
Office Version
  1. 365
Platform
  1. Windows
Hi Guys and Gals,

A quick question if I may:

Is it possible to have a macro that runs from one button to sort a range in ascending order AND descending order? Obviously not at the same time.

So: if column A is sorted ascendingly and then the button is pressed again, the macro would check the range - if it's sorted ascendingly already it will then reverse the order.

Many thanks for all the help!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
one suggestion would be to have a sentry value in another cell outwith the sort range, i would suggest you put the value 1 in the cell.

Create your button and macro to do the sort, add an IF statement around the sort code on the lines of

IF range("B1").value = 1 then
sort ascending
else
sort descending
end if
range("B1").value = range("B1").value * -1

this would change the sentry value between 1 and -1
 
Upvote 0
Hi jimrward,

Many thanks for your suggestion! I've incorporated it into my design and it works very well!

It also allows me to change my header based on the value assigned (1, 2 or nothing) to Heading ▲ or for ascending or descending using a standard if formula.

Sometimes I get too lost in the code that I forget you can use code in conjunction with cells! Thanks again for steering me to the right path.
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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