LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default XL2002 - Sort xlAscedending / xlDescending

Dear All

I have a simple table (with a header row) containing 5 columns - 3 of the
columns will need to be sorted by the user.
Above each of the columns that need sorting there is a shape that is used to
run the sorting macro.

Here's what I'd like to do.
1 - Rather than creating 3 macros to sort 3 columns I'd like to create one
that runs depending on which button, (or shape in this case), is selected.

2 - Depending on the current order of the sorted list, I'd like the macro to
do the opposite - i.e. if the list is currently xlAscending, next time the
button is pressed for that list, it sorts in xlDescending.

Code below - any help appreciated

Trevor Williams.
--------
Sub SortEachCol()
Dim shp As Shape
Set shp = ActiveSheet.Shapes(Application.Caller)
myCol = shp.TopLeftCell.Column 'this returns a column number, not letter

'this checks to see last sort order and sets myOrder to the opposite order
If Range("L13") = "xlAscending" Then
myOrder = "xlDescending"
Else
myOrder = "xlAscending"
End If

'this sorts the list - I need to chnge the Range("C:C") to Range(myCol)
'and set Order1:=myOrder
Range("C12:G24").Sort Key1:=Range("C:C"), Order1:=xlDescending,
Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:=xlSortNormal
'this updates the new sort order
Range("L13") = myOrder
End Sub
 
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
XL2002 SUM with a twist... Trevor Williams Excel Worksheet Functions 4 December 9th 09 10:28 AM
XL2002 - SeriesCollection.Index Trevor Williams Excel Programming 3 October 29th 07 03:05 PM
xl2002 problem Gary Keramidas Excel Programming 3 May 24th 07 04:18 AM
Semi-hang in XL2002 Charlie Excel Discussion (Misc queries) 0 May 6th 06 04:53 PM
Using min and max function XL2002 Extremely Aggravated Excel Worksheet Functions 1 September 23rd 05 06:29 PM


All times are GMT +1. The time now is 03:38 PM.

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

About Us

"It's about Microsoft Excel"