Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Sort by one column then another.

I want to do two sorts one on column "B" and then by column "E" for a
specific range.

Below is the sort for the first sort. How do I do a nested sort along whith
the below sort?

ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add Key:=Range _
("B6:B100"), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A6:E100")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 464
Default Sort by one column then another.

Assumes both Columns have headings

Sub SortAE()
Application.DisplayAlerts = False
'CODENAME
'http://www.ozgrid.com/VBA/excel-vba-sheet-names.htm
With Sheet1
.Range("B1", Cells(.Rows.Count, "B") _
.End(xlUp)).Sort .Range("B1"), xlAscending, , , , , , xlYes
.Range("E1", Cells(.Rows.Count, "E") _
.End(xlUp)).Sort .Range("E1"), xlAscending, , , , , , xlYes
End With
Application.DisplayAlerts = True
End Sub



--
Regards
Dave Hawley
www.ozgrid.com
"sort" wrote in message
...
I want to do two sorts one on column "B" and then by column "E" for a
specific range.

Below is the sort for the first sort. How do I do a nested sort along
whith
the below sort?

ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add Key:=Range _
("B6:B100"), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A6:E100")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Sort by one column then another.

hi
if you record a sort macro, it look something like this.

Range("A6:E100").Sort _
Key1:=Range("A2"), _
Order1:=xlAscending, _
Key2:=Range("B2"), _
Order2:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal

the recorder can be your friend.
besides, in the code you posted i didn't see any declared sort keys. it
looks like you set the first sort key to the range to sort. odd. does that
code accually work??

Regards
FSt1

"sort" wrote:

I want to do two sorts one on column "B" and then by column "E" for a
specific range.

Below is the sort for the first sort. How do I do a nested sort along whith
the below sort?

ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add Key:=Range _
("B6:B100"), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A6:E100")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

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 entire spreadsheet by one column sort jbclem Excel Discussion (Misc queries) 6 April 2nd 23 08:06 PM
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


All times are GMT +1. The time now is 03:47 PM.

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

About Us

"It's about Microsoft Excel"