#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 54
Default toggle sort columns

I have a button linked to a macro that will sort a data ascending. Is there
a way to click said button a second time and it will sord descending? Here's
the code thus far:

Sub sort_date()
Range("A3:T23").Sort Key1:=Range("G3"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default toggle sort columns

Hi,

This test g3 and G4 to see which way they are sorted and then does the cort
in the opposite direction.

Sub sort_date()
If Left(Range("G3"), 1) Left(Range("G4"), 1) Then
MyWay = xlAscending
Else
MyWay = xlDescending
End If
Range("A3:T23").Sort Key1:=Range("G3"), _
Order1:=MyWay, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

Mike

"JSnow" wrote:

I have a button linked to a macro that will sort a data ascending. Is there
a way to click said button a second time and it will sord descending? Here's
the code thus far:

Sub sort_date()
Range("A3:T23").Sort Key1:=Range("G3"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 913
Default toggle sort columns

If G3 and G4 are equal this macro will not work.
Better to compare G3 to G23, I think.

/ Lars-Åke

On Sun, 7 Dec 2008 07:36:01 -0800, Mike H
wrote:

Hi,

This test g3 and G4 to see which way they are sorted and then does the cort
in the opposite direction.

Sub sort_date()
If Left(Range("G3"), 1) Left(Range("G4"), 1) Then
MyWay = xlAscending
Else
MyWay = xlDescending
End If
Range("A3:T23").Sort Key1:=Range("G3"), _
Order1:=MyWay, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

Mike

"JSnow" wrote:

I have a button linked to a macro that will sort a data ascending. Is there
a way to click said button a second time and it will sord descending? Here's
the code thus far:

Sub sort_date()
Range("A3:T23").Sort Key1:=Range("G3"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default toggle sort columns

Ah,

I never thought of that, good idea.

Mike

"Lars-Ã…ke Aspelin" wrote:

If G3 and G4 are equal this macro will not work.
Better to compare G3 to G23, I think.

/ Lars-Ã…ke

On Sun, 7 Dec 2008 07:36:01 -0800, Mike H
wrote:

Hi,

This test g3 and G4 to see which way they are sorted and then does the cort
in the opposite direction.

Sub sort_date()
If Left(Range("G3"), 1) Left(Range("G4"), 1) Then
MyWay = xlAscending
Else
MyWay = xlDescending
End If
Range("A3:T23").Sort Key1:=Range("G3"), _
Order1:=MyWay, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

Mike

"JSnow" wrote:

I have a button linked to a macro that will sort a data ascending. Is there
a way to click said button a second time and it will sord descending? Here's
the code thus far:

Sub sort_date()
Range("A3:T23").Sort Key1:=Range("G3"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 54
Default toggle sort columns

Mike H, although I follow what's supposed to happen with this code, it
doesn't seem to work. The range, A4 (not A3, my bad) through T23 will sort
via row G4 but will only do so ascending. It doesn't switch to descending.

"Mike H" wrote:

Ah,

I never thought of that, good idea.

Mike

"Lars-Ã…ke Aspelin" wrote:

If G3 and G4 are equal this macro will not work.
Better to compare G3 to G23, I think.

/ Lars-Ã…ke

On Sun, 7 Dec 2008 07:36:01 -0800, Mike H
wrote:

Hi,

This test g3 and G4 to see which way they are sorted and then does the cort
in the opposite direction.

Sub sort_date()
If Left(Range("G3"), 1) Left(Range("G4"), 1) Then
MyWay = xlAscending
Else
MyWay = xlDescending
End If
Range("A3:T23").Sort Key1:=Range("G3"), _
Order1:=MyWay, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

Mike

"JSnow" wrote:

I have a button linked to a macro that will sort a data ascending. Is there
a way to click said button a second time and it will sord descending? Here's
the code thus far:

Sub sort_date()
Range("A3:T23").Sort Key1:=Range("G3"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub





  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default toggle sort columns

Hi,

Modified and including the suggestion made by Lars-Ã…ke


Sub sort_date()
If Left(Range("G4"), 1) Left(Range("G23"), 1) Then
MyWay = xlAscending
Else
MyWay = xlDescending
End If
Range("A4:T23").Sort Key1:=Range("G3"), _
Order1:=MyWay, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

Mike

"JSnow" wrote:

Mike H, although I follow what's supposed to happen with this code, it
doesn't seem to work. The range, A4 (not A3, my bad) through T23 will sort
via row G4 but will only do so ascending. It doesn't switch to descending.

"Mike H" wrote:

Ah,

I never thought of that, good idea.

Mike

"Lars-Ã…ke Aspelin" wrote:

If G3 and G4 are equal this macro will not work.
Better to compare G3 to G23, I think.

/ Lars-Ã…ke

On Sun, 7 Dec 2008 07:36:01 -0800, Mike H
wrote:

Hi,

This test g3 and G4 to see which way they are sorted and then does the cort
in the opposite direction.

Sub sort_date()
If Left(Range("G3"), 1) Left(Range("G4"), 1) Then
MyWay = xlAscending
Else
MyWay = xlDescending
End If
Range("A3:T23").Sort Key1:=Range("G3"), _
Order1:=MyWay, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

Mike

"JSnow" wrote:

I have a button linked to a macro that will sort a data ascending. Is there
a way to click said button a second time and it will sord descending? Here's
the code thus far:

Sub sort_date()
Range("A3:T23").Sort Key1:=Range("G3"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub


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
Sort by color: Is there an easy way to sort columns or rows in EX MGP Excel Worksheet Functions 5 August 16th 08 11:28 AM
sort by two columns ends up with wrong sort in 2nd col urbnjckct Excel Discussion (Misc queries) 3 November 2nd 07 01:25 AM
Sort command does not sort some columns? BillyBob New Users to Excel 4 May 11th 06 04:16 PM
How do I sort the data in 8 columns by two of the columns? Sorting Excel Worksheet Functions 1 October 25th 05 03:57 PM
data sort is not including all columns in sort Tracy Excel Discussion (Misc queries) 1 October 4th 05 12:16 AM


All times are GMT +1. The time now is 07:31 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"