LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
dcbpe
 
Posts: n/a
Default Macro sorting by 4 columns

I have a spreadsheet with a variable number of rows, which I need to sort by
4 columns (A, B, D, and C). Via menu, you can only sort by 3 columns
w/Excel, so I recorded the macro and tried to edit it to add the 4th
Key...but it doesn't work.

I've edited macros before without an error, so I'm somewhat at a loss to
figure out what the heck I'm doing wrong. Is Excel simply incapable of
sorting by 4 columns? Will I have to use QPro for this file?

Here is the 3 column sort code, as recorded:
Sub SortxManager()
'
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Sort Key1:=Range("A4"), Order1:=xlAscending, Key2:=Range("B4") _
, Order2:=xlAscending, Key3:=Range("D4"), Order3:=xlAscending,
Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
Range("A4").Select
End Sub


Here is the 4 column version that doesn't work:
Sub SortxManager()
'
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Sort Key1:=Range("A4"), Order1:=xlAscending, Key2:=Range("B4") _
, Order2:=xlAscending, Key3:=Range("D4"), Order3:=xlAscending, _
Key4:=Range("C4"), Order4:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal, DataOption4:=xlSortNormal
Range("A4").Select
End Sub


What am I doing wrong? Thanks in advance...



 
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
macro to unmerge columns HankY Excel Discussion (Misc queries) 2 December 8th 05 06:04 AM
Sorting Columns on HTML file created in Excel Terri and Rob Excel Discussion (Misc queries) 2 December 4th 05 03:06 AM
Macro for resizing of columns? MatthewTap Excel Discussion (Misc queries) 2 December 1st 05 06:48 PM
Editing a simple macro Connie Martin Excel Worksheet Functions 5 November 29th 05 09:19 PM
How to keep rows together when sorting columns? Amit Excel Worksheet Functions 1 March 28th 05 06:01 PM


All times are GMT +1. The time now is 02:01 AM.

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

About Us

"It's about Microsoft Excel"