Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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
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
Sort Macro BAKERSMAN Excel Discussion (Misc queries) 0 March 24th 10 05:34 AM
sort macro Jean-Marie Excel Discussion (Misc queries) 8 February 5th 10 04:29 PM
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
Using Macro to sort without clicking on macro button dd Excel Discussion (Misc queries) 3 May 3rd 07 06:00 PM
sort macro Randy Starkey Excel Programming 5 March 25th 05 01:59 AM


All times are GMT +1. The time now is 06:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"