How do I alternate a sort from a text box via macros?

G

Guest

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.
 
S

STEVE BELL

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top