Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
formula to sort a range so that it matches the exact rows of a column that is outside that range? | Excel Discussion (Misc queries) | |||
HOW DO YOU SPECIFY A RANGE TO SORT? | Excel Worksheet Functions | |||
Can I sort by Range Name? | Excel Discussion (Misc queries) | |||
Sort range changes during sort | Excel Discussion (Misc queries) | |||
Sort a Range | Excel Discussion (Misc queries) |