Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Button Code to Alternate Sort Order ?

Paul,

The following seems to work.
Change the A1 cell as desired...
'---------------------------------------------------
Sub SortCity()
Dim SortOrder As Long

With Range("A1")
If .Value < 1 Or .Value 2 Then .Value = 1
SortOrder = .Value
End With

Application.Goto Reference:="Data"
Selection.Sort Key1:=Range("G4"), Order1:=SortOrder, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A1").Value = (3 - SortOrder)
End Sub
'---------------------------------------------------
Regards,
Jim Cone
San Francisco, CA

"Paul Cross" wrote in message om...
I've got a range called "Data" and a column called "City" and a button
called SortCity on top of that column. I've recorded a macro that
sorts the column (ASCENDING). How do I adjust the code so that
alternate clicks on the button sort ASCENDING then DESCENDING, etc.

My code thus far:
Sub SortCity()
' SortCity Macro
' Macro recorded 11/12/2004 by pcross
Application.Goto Reference:="Data"
Selection.Sort Key1:=Range("G4"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub
I tried If / Then logic with a variable (eg assign it 1, then 0, etc.)
and also tried If / Then logic by comparing the first cell with the
last (and ASC sort if it's less than, etc) but in both cases the sort
order didn't change.
Thanks for help,
Paul Cross

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code for variable sort order Jacob Skaria Excel Discussion (Misc queries) 1 April 28th 10 02:26 PM
Retaining Sort order in the Sort Dialog box CBittinger Excel Discussion (Misc queries) 2 January 9th 08 05:01 PM
Sort sheet based on particuilar sort order Also Excel Worksheet Functions 4 January 3rd 08 09:31 AM
sort last name order amolano8 Excel Discussion (Misc queries) 2 August 17th 06 06:24 PM
sort order DGNVSPORTS Excel Discussion (Misc queries) 3 June 7th 05 07:19 PM


All times are GMT +1. The time now is 08:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"