ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I alternate a sort from a text box via macros? (https://www.excelbanter.com/excel-programming/331299-how-do-i-alternate-sort-text-box-via-macros.html)

g.a.

How do I alternate a sort from a text box via macros?
 
I have a column of data that I am using a text box to run a macro that sorts
the data in descending order. How can I alternate the sort criteria
(ascending/descending) using the same text box? Push once - sort in
ascending order; push again - sort in descending order. Thanks.

STEVE BELL

How do I alternate a sort from a text box via macros?
 
Here's a down and dirty method

Dim x As Long, ordr As Long

x = MsgBox("Sort Ascending (Yes), Descending (No)", vbYesNo)

If x = 6 Then ' 6 = Yes
ordr = 1 ' 1 = ascending
Else
ordr = 2 ' 2 = descending
End If

Range("E:E").Sort Key1:=Range("E1"), Order1:=ordr, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom


--
steveB

Remove "AYN" from email to respond
"g.a." wrote in message
...
I have a column of data that I am using a text box to run a macro that
sorts
the data in descending order. How can I alternate the sort criteria
(ascending/descending) using the same text box? Push once - sort in
ascending order; push again - sort in descending order. Thanks.





All times are GMT +1. The time now is 01:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com