Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Sorting - Finding last row

I want a commandbutton to sort A3:Q. Though column Q is included in the
range, the cells in column Q may be empty. Therefore, I need to locate the
last row using column A, then sort A3:Q(lastrow).

Here is the code I was working with:

Private Sub CommandButton3_Click()
Lastrow = Range("A65536").End(xlUp).Select
Range("A3:Q" & Lastrow).Select
Selection.Sort Key1:=Range("A3"), Order1:=xlAscending, Key2:=Range("B3") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
End Sub

Thanks for your help!

Les
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,805
Default Sorting - Finding last row

Use
LastRow = Range("A65536").End(xlUp).Row
instead of
Lastrow = Range("A65536").End(xlUp).Select


"WLMPilot" wrote:

I want a commandbutton to sort A3:Q. Though column Q is included in the
range, the cells in column Q may be empty. Therefore, I need to locate the
last row using column A, then sort A3:Q(lastrow).

Here is the code I was working with:

Private Sub CommandButton3_Click()
Lastrow = Range("A65536").End(xlUp).Select
Range("A3:Q" & Lastrow).Select
Selection.Sort Key1:=Range("A3"), Order1:=xlAscending, Key2:=Range("B3") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
End Sub

Thanks for your help!

Les

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Sorting - Finding last row

Thanks. Worked great!!

"Sheeloo" wrote:

Use
LastRow = Range("A65536").End(xlUp).Row
instead of
Lastrow = Range("A65536").End(xlUp).Select


"WLMPilot" wrote:

I want a commandbutton to sort A3:Q. Though column Q is included in the
range, the cells in column Q may be empty. Therefore, I need to locate the
last row using column A, then sort A3:Q(lastrow).

Here is the code I was working with:

Private Sub CommandButton3_Click()
Lastrow = Range("A65536").End(xlUp).Select
Range("A3:Q" & Lastrow).Select
Selection.Sort Key1:=Range("A3"), Order1:=xlAscending, Key2:=Range("B3") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
End Sub

Thanks for your help!

Les

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Sorting - Finding last row

If you have any intention of moving to Excel 2007, I'd recommend doing this

Dim aWS as Worksheet

set aWS = activesheet

lastRow = aws.cells(aws.rows.count,1).end(xlup).row

--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"WLMPilot" wrote:

Thanks. Worked great!!

"Sheeloo" wrote:

Use
LastRow = Range("A65536").End(xlUp).Row
instead of
Lastrow = Range("A65536").End(xlUp).Select


"WLMPilot" wrote:

I want a commandbutton to sort A3:Q. Though column Q is included in the
range, the cells in column Q may be empty. Therefore, I need to locate the
last row using column A, then sort A3:Q(lastrow).

Here is the code I was working with:

Private Sub CommandButton3_Click()
Lastrow = Range("A65536").End(xlUp).Select
Range("A3:Q" & Lastrow).Select
Selection.Sort Key1:=Range("A3"), Order1:=xlAscending, Key2:=Range("B3") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
End Sub

Thanks for your help!

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
Automatic sorting (giving max and min) based on custom sorting lis Joe Lewis[_2_] Excel Worksheet Functions 4 November 23rd 08 05:12 AM
Excel Sorting - Finding Duplicate Entries Roxanne Excel Programming 1 January 16th 08 03:22 PM
finding, sorting, put only part of a cell Debilee Excel Worksheet Functions 4 October 10th 07 11:01 PM
Finding Duplicates in a Column (Without Sorting) ConfusedNHouston Excel Discussion (Misc queries) 3 February 14th 07 02:24 PM
Sorting and Finding data SamGB Excel Discussion (Misc queries) 1 May 25th 06 08:19 PM


All times are GMT +1. The time now is 04:21 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"