Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Sorting macro

I am trying to write a macro that will sort a spreadsheet by certain
header definitions rather than by column.

Simply recording the action as a macro only registers the columns to be
sorted by, not the header definitions.

Does anyone know how this can be done?

Many thanks
Simon



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Sorting macro

The sort command only will accept column locations. You need to build code
that translates your header names into column locations and pass the column
locations to the sort command. An alternative would be to assign names to
the cells containing the headers which match the values of the headers.
Then you could use those as arguments to the key values.

My headers were

Header1 Header2 Header3 Header4
A B 100 230
C A 250 20

etc.

I named the cell (Insert=Name=Define) with Header1, Header1 and so forth.
This worked:

Range("B2").Sort _
Key1:="Header1", Order1:=xlAscending, _
Key2:="Header2", Order2:=xlDescending, _
Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom



--
Regards,
Tom Ogilvy


"Simon" wrote in message
...
I am trying to write a macro that will sort a spreadsheet by certain
header definitions rather than by column.

Simply recording the action as a macro only registers the columns to be
sorted by, not the header definitions.

Does anyone know how this can be done?

Many thanks
Simon



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



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
Sorting Macro Jamie Excel Worksheet Functions 4 September 18th 09 06:53 PM
Help with Macro for sorting Brad[_6_] Excel Worksheet Functions 2 August 10th 09 04:20 PM
sorting using macro Ross Excel Discussion (Misc queries) 2 September 15th 05 10:13 PM
Sorting w/Macro Joe[_24_] Excel Programming 1 August 28th 03 07:44 PM
sorting macro Beth Mc[_2_] Excel Programming 2 August 1st 03 03:49 AM


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