Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm trying to create a small VBA program for sorting a range by 3
paramters by using the Recording Macro tool. the table to sort is varying by the rows between times of sorting Before begining the recording I choose the active cell to be on the table header row and then entered the following sequensce: <end <left arrow <shift<end<down arrow (while continue holding the <shift) <left aroow 13 times - to reach the right botom of the table (some of the culomns are not filled) and then I did the sorting. following is what was actually recorded: Selection.End(xlToLeft).Select Range(Selection, Selection.End(xlDown)).Select ActiveCell.Range("A1:N1511").Select Selection.Sort Key1:=ActiveCell.Offset(0, 11).Range("A1"), Order1:= _ xlAscending, Key2:=ActiveCell.Offset(0, 13).Range("A1"), Order2:=xlAscending _ , Key3:=ActiveCell.Offset(0, 8).Range("A1"), Order3:=xlAscending, Header:= _ xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _ xlSortNormal End Sub in the 3rd row the range was transormed to fix range (?) how to fix it? Regards, nk |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
hi,
The recorder will sometimes adds extra and unnecessary lines of code. The recorder is a good way to start a macro but it's always a good idea to go back and clean it up. Replace the first three lines with..... 1.Range("A1").Select Range(Range("A1"), Range("A1").End(xlToRight).End(xlDown)).Select OR 2.Range("A1").Select ActiveCell.CurrentRegion.Select Either way should work. regards FSt1 "nk" wrote: I'm trying to create a small VBA program for sorting a range by 3 paramters by using the Recording Macro tool. the table to sort is varying by the rows between times of sorting Before begining the recording I choose the active cell to be on the table header row and then entered the following sequensce: <end <left arrow <shift<end<down arrow (while continue holding the <shift) <left aroow 13 times - to reach the right botom of the table (some of the culomns are not filled) and then I did the sorting. following is what was actually recorded: Selection.End(xlToLeft).Select Range(Selection, Selection.End(xlDown)).Select ActiveCell.Range("A1:N1511").Select Selection.Sort Key1:=ActiveCell.Offset(0, 11).Range("A1"), Order1:= _ xlAscending, Key2:=ActiveCell.Offset(0, 13).Range("A1"), Order2:=xlAscending _ , Key3:=ActiveCell.Offset(0, 8).Range("A1"), Order3:=xlAscending, Header:= _ xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _ xlSortNormal End Sub in the 3rd row the range was transormed to fix range (?) how to fix it? Regards, nk |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Define Name range | Excel Discussion (Misc queries) | |||
Define a range | Excel Discussion (Misc queries) | |||
how to define a range in VBA | Excel Programming | |||
Define a range based on another named range | Excel Worksheet Functions | |||
Define Range Name | Excel Programming |