Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to sort
I need a macro that will take a list and sort by last name (B:B) with the
first row of data being row 3. The user will be adding names at the end of the list and then press a command button to sort in ascending order. I know xlUp needs to be used but not sure how to place it in the code. The column range is A:N. Column headers are in row 2. Thanks, Les |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to sort
Recorded Macro:
Sub Macro1() Range("A2").Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlToRight)).Select Selection.Sort Key1:=Range("B3"), Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End Sub Slightly different style (to find the last used cell): Sub Macro1() Cells(Rows.Count, "A").End(xlUp).Select Range(Selection, Selection.End(xlUp)).Select Range(Selection, Selection.End(xlToRight)).Select Selection.Sort Key1:=Range("B3"), Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End Sub Regards, Ryan-- -- RyGuy "WLMPilot" wrote: I need a macro that will take a list and sort by last name (B:B) with the first row of data being row 3. The user will be adding names at the end of the list and then press a command button to sort in ascending order. I know xlUp needs to be used but not sure how to place it in the code. The column range is A:N. Column headers are in row 2. Thanks, Les |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to sort
FirstRow = 3 LastRow = Range("B" & Rows.Count).End(xlUp).Row Set SortRange = Range("A" & FirstRow & ":N" & LastRow) SortRange.Sort _ Key1:=Range("B1"), _ Order1:=xlAscending, _ Header:=xlGuess "WLMPilot" wrote: I need a macro that will take a list and sort by last name (B:B) with the first row of data being row 3. The user will be adding names at the end of the list and then press a command button to sort in ascending order. I know xlUp needs to be used but not sure how to place it in the code. The column range is A:N. Column headers are in row 2. Thanks, Les |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Sort Macro | Excel Discussion (Misc queries) | |||
sort macro | Excel Discussion (Misc queries) | |||
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort | Excel Worksheet Functions | |||
Using Macro to sort without clicking on macro button | Excel Discussion (Misc queries) | |||
sort macro | Excel Programming |