Forum Statistics
- Forum Members:
- Total Threads:
- Total Posts: 4
There are 1 users currently browsing forums.
|
 |

09-04-2007, 06:47 PM
|
|
Registered User
|
|
Join Date: 24 Dec 2003
Posts: 15
|
|
|
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.
|

09-04-2007, 07:00 PM
|
|
Valued Forum Contributor
|
|
Join Date: 05 Jul 2007
Location: Lexington, MA
Posts: 301
|
|
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
|

09-06-2007, 02:26 PM
|
|
Registered User
|
|
Join Date: 24 Dec 2003
Posts: 15
|
|
|
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!!
|

09-06-2007, 03:03 PM
|
|
Valued Forum Contributor
|
|
Join Date: 11 Apr 2006
Posts: 407
|
|
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.
|
 |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|