Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Range.Sort in VBA

I recorded a sorting procedure with the macrorecorder:

Range("A1:X4661").Sort Key1:=Range("A2"),
Order1:=xlAscending, Key2:= _
Range("F2"), Order2:=xlDescending,
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal

I want this to be flexible, so if I add rows, the macro
still works. So I have to get the hardcoding away in Range
("A1:X4661").Sort ... and get something like

Range("A1:X" & variableLngLastLine & ").Sort Key1:=Range
("A2"), Order1:=xlAscending, Key2:= _
Range("F2"), Order2:=xlDescending,
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal

This doesn´t work however. Can anybody help me how to
softcode the hardcode macro in VBA?

TIA

MArtin
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Range.Sort in VBA

Try A:X instead of A1:X.

Jeff

"Martin Los" wrote in message
...
I recorded a sorting procedure with the macrorecorder:

Range("A1:X4661").Sort Key1:=Range("A2"),
Order1:=xlAscending, Key2:= _
Range("F2"), Order2:=xlDescending,
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal

I want this to be flexible, so if I add rows, the macro
still works. So I have to get the hardcoding away in Range
("A1:X4661").Sort ... and get something like

Range("A1:X" & variableLngLastLine & ").Sort Key1:=Range
("A2"), Order1:=xlAscending, Key2:= _
Range("F2"), Order2:=xlDescending,
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal

This doesn´t work however. Can anybody help me how to
softcode the hardcode macro in VBA?

TIA

MArtin


  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Range.Sort in VBA

I must have been thinking:
"Why do it the hard way if you can do it the simple way?"


Thanks Jeff!! It works great!

-----Original Message-----
Try A:X instead of A1:X.

Jeff

"Martin Los" wrote

in message
...
I recorded a sorting procedure with the macrorecorder:

Range("A1:X4661").Sort Key1:=Range("A2"),
Order1:=xlAscending, Key2:= _
Range("F2"), Order2:=xlDescending,
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal

I want this to be flexible, so if I add rows, the macro
still works. So I have to get the hardcoding away in Range
("A1:X4661").Sort ... and get something like

Range("A1:X" & variableLngLastLine & ").Sort Key1:=Range
("A2"), Order1:=xlAscending, Key2:= _
Range("F2"), Order2:=xlDescending,
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal

This doesn´t work however. Can anybody help me how to
softcode the hardcode macro in VBA?

TIA

MArtin


.

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
formula to sort a range so that it matches the exact rows of a column that is outside that range? steveo Excel Discussion (Misc queries) 1 June 18th 06 02:05 AM
HOW DO YOU SPECIFY A RANGE TO SORT? george Excel Worksheet Functions 2 June 7th 06 06:08 AM
Can I sort by Range Name? DeepSouthRick Excel Discussion (Misc queries) 1 June 2nd 05 03:06 AM
Sort range changes during sort coffedrinker2003 Excel Discussion (Misc queries) 1 May 24th 05 11:53 PM
Sort a Range Brandt Excel Discussion (Misc queries) 5 December 28th 04 10:45 AM


All times are GMT +1. The time now is 10:54 AM.

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"