Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 09-04-2007, 06:47 PM
rglasunow rglasunow is offline
Registered User
 
Join Date: 24 Dec 2003
Posts: 15
rglasunow is becoming part of the community
Sorting Using VBA

Please Register to Remove these Ads

I am trying to sort three different columns using VBA. I am running into several issues. Below is the code I currently have.

Range("Pending").sort Key1:=Range("V5"), Order1:=xlDescending, Key2:=Range("W5") _
, Order2:=xlDescending, Key3:=Range("X5"), Order3:=xlDescending, Header _
:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom _
, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
Range("V5").Select
Selection.End(xlDown).Select

Here’s what I’m trying to achieve.

• Highlight the entire row from row 5 down to the very last data cell in column A.
• Sort in order by column V, W then X.

I’m having trouble selecting the entire row and having the selection stop at the last cell in column A.

Any help is greatly appreciated.

Thanks.
Reply With Quote
  #2  
Old 09-04-2007, 07:00 PM
FrankBoston FrankBoston is offline
Valued Forum Contributor
 
Join Date: 05 Jul 2007
Location: Lexington, MA
Posts: 301
FrankBoston is becoming part of the community
Maybe this will do it:
Code:
Range("Pending").EntireRow.Sort _
     Key1:=Range("V5"), Order1:=xlDescending, DataOption1:=xlSortNormal, _
     Key2:=Range("W5"), Order2:=xlDescending, DataOption2:=xlSortNormal, _
     Key3:=Range("X5"), Order3:=xlDescending, DataOption3:=xlSortNormal, _
     Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom_

Range("V5").End(xlDown).Select
__________________
FrankBoston is the pen name for Andrew Garland, Lexington MA
Reply With Quote
  #3  
Old 09-06-2007, 02:26 PM
rglasunow rglasunow is offline
Registered User
 
Join Date: 24 Dec 2003
Posts: 15
rglasunow is becoming part of the community
Thanks for your help Frank but unfortunately this didn’t work. Does anyone have any other suggestions to what I’m trying to achieve (see above).

Thank you!!
Reply With Quote
  #4  
Old 09-06-2007, 03:03 PM
Ikaabod Ikaabod is offline
Valued Forum Contributor
 
Join Date: 11 Apr 2006
Posts: 407
Ikaabod is becoming part of the community
I'm assuming your sort is already set up properly and that you just need the code for the proper selection. In which case, this code should work:
Code:
iLastRow = Range("A" & Rows.Count).End(xlUp).Row
Range("A5:A" & iLastRow).EntireRow.Select
Selection.Sort Key1:=Range("V5"), Order1:=xlDescending, Key2:=Range("W5") _
, Order2:=xlDescending, Key3:=Range("X5"), Order3:=xlDescending, Header _
:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom _
, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
Hope that's what you need.
Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump