Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default 4 column sort... Fools rush in....

Not knowing any better, I took the recorded code for a 3 column sort and
tried to turn it into a 4 column sort. Got run time 1004 object error. Code
is below.

Is it possible to do what I'm trying this way? I'd rather not have to select
different ranges of cells and do a 3 column sort, but I may have to.
So, have I made an error in the code, or is it just not possible?
Thanks.


Sub zsortbcda()
Application.ScreenUpdating = False

Columns("A:D").Select

Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, _
Key2:=Range("C1"), Order2:=xlAscending, _
Key3:=Range("D1"), Order3:=xlAscending, _
Key4:=Range("A1"), Order4:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal, DataOption4:=xlSortNormal

Range("A1").Select

Application.ScreenUpdating = True
End Sub
--
Neal Z
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default 4 column sort... Fools rush in....

Sort only works on a maximum of three columns at a time. Do two
consecutive sorts - the first on the three least-important columns, then
the second on the most important.

In article ,
Neal Zimm wrote:

Not knowing any better, I took the recorded code for a 3 column sort and
tried to turn it into a 4 column sort. Got run time 1004 object error. Code
is below.

Is it possible to do what I'm trying this way? I'd rather not have to select
different ranges of cells and do a 3 column sort, but I may have to.
So, have I made an error in the code, or is it just not possible?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default 4 column sort... Fools rush in....

Thanks for the tip 3 least important (minor, semantics, but all the
columns are important). I was doing 2 cols and 2 cols and getting results I
didn't like.

"JE McGimpsey" wrote:

Sort only works on a maximum of three columns at a time. Do two
consecutive sorts - the first on the three least-important columns, then
the second on the most important.

In article ,
Neal Zimm wrote:

Not knowing any better, I took the recorded code for a 3 column sort and
tried to turn it into a 4 column sort. Got run time 1004 object error. Code
is below.

Is it possible to do what I'm trying this way? I'd rather not have to select
different ranges of cells and do a 3 column sort, but I may have to.
So, have I made an error in the code, or is it just not possible?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default 4 column sort... Fools rush in....

Hi Neal,

Probably you are asking for a code which could do 4 column sort in ONE
sorting operation. I dont know about that.

But programmatically you could do TWO sorting operations like the following
and get the SAME results.

Selection.Sort Key1:=Range("C1"), Order1:=xlAscending, _
Key2:=Range("D1"), Order2:=xlAscending, _
Key3:=Range("A1"), Order3:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal,

Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, _
Key2:=Range("C1"), Order2:=xlAscending, _
Key3:=Range("D1"), Order3:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal,

Modify it to your requirements

Thanks a lot,
Hari
India


"Neal Zimm" wrote in message
...
Not knowing any better, I took the recorded code for a 3 column sort and
tried to turn it into a 4 column sort. Got run time 1004 object error.
Code
is below.

Is it possible to do what I'm trying this way? I'd rather not have to
select
different ranges of cells and do a 3 column sort, but I may have to.
So, have I made an error in the code, or is it just not possible?
Thanks.


Sub zsortbcda()
Application.ScreenUpdating = False

Columns("A:D").Select

Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, _
Key2:=Range("C1"), Order2:=xlAscending, _
Key3:=Range("D1"), Order3:=xlAscending, _
Key4:=Range("A1"), Order4:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal, DataOption4:=xlSortNormal

Range("A1").Select

Application.ScreenUpdating = True
End Sub
--
Neal Z



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default 4 column sort... Fools rush in....

Thanks. That's what I ended up doing.

"Hari Prasadh" wrote:

Hi Neal,

Probably you are asking for a code which could do 4 column sort in ONE
sorting operation. I dont know about that.

But programmatically you could do TWO sorting operations like the following
and get the SAME results.

Selection.Sort Key1:=Range("C1"), Order1:=xlAscending, _
Key2:=Range("D1"), Order2:=xlAscending, _
Key3:=Range("A1"), Order3:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal,

Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, _
Key2:=Range("C1"), Order2:=xlAscending, _
Key3:=Range("D1"), Order3:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal,

Modify it to your requirements

Thanks a lot,
Hari
India


"Neal Zimm" wrote in message
...
Not knowing any better, I took the recorded code for a 3 column sort and
tried to turn it into a 4 column sort. Got run time 1004 object error.
Code
is below.

Is it possible to do what I'm trying this way? I'd rather not have to
select
different ranges of cells and do a 3 column sort, but I may have to.
So, have I made an error in the code, or is it just not possible?
Thanks.


Sub zsortbcda()
Application.ScreenUpdating = False

Columns("A:D").Select

Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, _
Key2:=Range("C1"), Order2:=xlAscending, _
Key3:=Range("D1"), Order3:=xlAscending, _
Key4:=Range("A1"), Order4:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal, DataOption4:=xlSortNormal

Range("A1").Select

Application.ScreenUpdating = True
End Sub
--
Neal Z






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default 4 column sort... Fools rush in....

Did you try looking at Help for Sort? It works the same way in VBA as it does
when invoked from the Data menu.

On Thu, 3 Feb 2005 21:19:02 -0800, Neal Zimm wrote:

Not knowing any better, I took the recorded code for a 3 column sort and
tried to turn it into a 4 column sort. Got run time 1004 object error. Code
is below.

Is it possible to do what I'm trying this way? I'd rather not have to select
different ranges of cells and do a 3 column sort, but I may have to.
So, have I made an error in the code, or is it just not possible?
Thanks.


Sub zsortbcda()
Application.ScreenUpdating = False

Columns("A:D").Select

Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, _
Key2:=Range("C1"), Order2:=xlAscending, _
Key3:=Range("D1"), Order3:=xlAscending, _
Key4:=Range("A1"), Order4:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal, DataOption4:=xlSortNormal

Range("A1").Select

Application.ScreenUpdating = True
End Sub


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default 4 column sort... Fools rush in....

Thanks. Help only mentions 3 columns too.
What I ended up doing is that the data allowed me to concatenate two of the
fields into one, so I could sort on 4 fields worth of data in "3" columns.


"Myrna Larson" wrote:

Did you try looking at Help for Sort? It works the same way in VBA as it does
when invoked from the Data menu.

On Thu, 3 Feb 2005 21:19:02 -0800, Neal Zimm wrote:

Not knowing any better, I took the recorded code for a 3 column sort and
tried to turn it into a 4 column sort. Got run time 1004 object error. Code
is below.

Is it possible to do what I'm trying this way? I'd rather not have to select
different ranges of cells and do a 3 column sort, but I may have to.
So, have I made an error in the code, or is it just not possible?
Thanks.


Sub zsortbcda()
Application.ScreenUpdating = False

Columns("A:D").Select

Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, _
Key2:=Range("C1"), Order2:=xlAscending, _
Key3:=Range("D1"), Order3:=xlAscending, _
Key4:=Range("A1"), Order4:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal, DataOption4:=xlSortNormal

Range("A1").Select

Application.ScreenUpdating = True
End Sub



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default 4 column sort... Fools rush in....

Hi
You can do as many sorts as you like - but only 3 at anyone time. Sorts in
Excel are persistent, so if you start with the lowest order sort key and end
with the highest order you will get the result you require.


--
Cheers
Nigel



"Neal Zimm" wrote in message
...
Not knowing any better, I took the recorded code for a 3 column sort and
tried to turn it into a 4 column sort. Got run time 1004 object error.

Code
is below.

Is it possible to do what I'm trying this way? I'd rather not have to

select
different ranges of cells and do a 3 column sort, but I may have to.
So, have I made an error in the code, or is it just not possible?
Thanks.


Sub zsortbcda()
Application.ScreenUpdating = False

Columns("A:D").Select

Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, _
Key2:=Range("C1"), Order2:=xlAscending, _
Key3:=Range("D1"), Order3:=xlAscending, _
Key4:=Range("A1"), Order4:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal, DataOption4:=xlSortNormal

Range("A1").Select

Application.ScreenUpdating = True
End Sub
--
Neal Z



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default 4 column sort... Fools rush in....

Thanks. I hadn't gotten to the combo yet of doing the minor fields first.
What I actually ended up doing is that I was lucky in that my data in two of
the columns allowed me to concatenate into another cell so I ended up sorting
on 3 columns, but '4columns worth' of data.

"Nigel" wrote:

Hi
You can do as many sorts as you like - but only 3 at anyone time. Sorts in
Excel are persistent, so if you start with the lowest order sort key and end
with the highest order you will get the result you require.


--
Cheers
Nigel



"Neal Zimm" wrote in message
...
Not knowing any better, I took the recorded code for a 3 column sort and
tried to turn it into a 4 column sort. Got run time 1004 object error.

Code
is below.

Is it possible to do what I'm trying this way? I'd rather not have to

select
different ranges of cells and do a 3 column sort, but I may have to.
So, have I made an error in the code, or is it just not possible?
Thanks.


Sub zsortbcda()
Application.ScreenUpdating = False

Columns("A:D").Select

Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, _
Key2:=Range("C1"), Order2:=xlAscending, _
Key3:=Range("D1"), Order3:=xlAscending, _
Key4:=Range("A1"), Order4:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal, DataOption4:=xlSortNormal

Range("A1").Select

Application.ScreenUpdating = True
End Sub
--
Neal Z




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
How to sort without including column headings in sort OPDvolunteer Excel Discussion (Misc queries) 4 March 11th 09 04:08 PM
Auto-Sort Won't Sort All Column Cells TikiTembo Excel Discussion (Misc queries) 1 March 25th 08 07:00 PM
data, sort option is grayed. how to sort on a column? Steve Richter Excel Discussion (Misc queries) 1 September 25th 07 03:25 PM
How can I sort one column and have the entire row sort. (binding) Blue Excel Worksheet Functions 10 November 13th 05 07:09 PM
April Fools Edgar[_3_] Excel Programming 3 April 1st 04 08:54 PM


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