![]() |
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 |
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 |
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 |
All times are GMT +1. The time now is 12:07 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com