Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #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...



  #2   Report Post  
Posted to microsoft.public.excel.misc
Dav
 
Posts: n/a
Default Macro sorting by 4 columns


If normally you sort by column C. Then do a sort by A B D as your 3
columns you would get the result you require.

You could even record this as a keystroke macros

Regards

Dav


--
Dav
------------------------------------------------------------------------
Dav's Profile: http://www.excelforum.com/member.php...o&userid=27107
View this thread: http://www.excelforum.com/showthread...hreadid=555615

  #3   Report Post  
Posted to microsoft.public.excel.misc
dcbpe
 
Posts: n/a
Default Macro sorting by 4 columns

"Dav" wrote:
If normally you sort by column C. Then do a sort by A B D as your 3
columns you would get the result you require.

You could even record this as a keystroke macros


I cannot do this, this is what the help function in excel tells you to do
for a four column sort. Unfortunatley, I need to sort all 4 columns on the
fly.

Sorting by column A separates a list 175 projects into 6 different sections
by project manager. Sorting by column B then organizes each managers
projects by town, sorting by D then organizes each town's project by project
number. In some instances, with larger projects, project numbers in column D
are further organized into different project phases, so I need to take the
sort to a fourth column to sort by project name within the project numbers.
The rest of the data in each row of the spreadsheet are a twelve week
man-hours projection for our design staff, each of which is tied to a
specific project name.

If I were to sort by manager (A), I would then need to sort each managers
projects by the remaining three columns. Hence, I would need 7 macros (and
as we get more managers, more macros). In each managers case, the number of
sort rows change dependant on insertion of new projects/designers and
deletion of closed projects. I have no way to accuratley set the selection
range for each manager, so I would have to run the sort smanually, every week
when the manhours projection updates.

I run Quattro Pro on my home PC and can run a five column sort direct from
the sort menu, and I've gone up to 8 within a macro. Qpro did that 11 years
ago (my first employer didn't use Excel). I have to beleive that Excel 2003
is as capable as QPro 1995...certainly not thru the menu, which obviously
only allows the three column sort, but at least within a macro.

Thanks for taking a stab at it though!
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
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 07:16 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"