#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 125
Default Sorting

With a cell selected in a bold header row, clcking the 'Sort Ascending'
button on the toolbar does exactly what I want.

It would be great to be able to put something this into a macro

Cells(2, 3). Sort, Order1:=xlAscending

but if I record a particular situation I get

ActiveCell.Offset(-1, 0).Range("A1:D75").Sort
Key1:=ActiveCell.Offset(-1, 1). _
Range("A1"), Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortNormal

which is specific in that it is picking up the particular range which will
change in the sheet I am wanting to sort.

Any suggestions for a universal sorting macro - ok xlAscending and the other
bits can be set.

Francis Hookham


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Sorting

I've had excellent results with changing "Header:=xlGuess" to
"Header:=xlYes" .. since it's not a function I've needed to use often I
cannot tell you the specifics as to why it works better, but it does.


Francis Hookham wrote:
With a cell selected in a bold header row, clcking the 'Sort Ascending'
button on the toolbar does exactly what I want.

It would be great to be able to put something this into a macro

Cells(2, 3). Sort, Order1:=xlAscending

but if I record a particular situation I get

ActiveCell.Offset(-1, 0).Range("A1:D75").Sort
Key1:=ActiveCell.Offset(-1, 1). _
Range("A1"), Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortNormal

which is specific in that it is picking up the particular range which will
change in the sheet I am wanting to sort.

Any suggestions for a universal sorting macro - ok xlAscending and the other
bits can be set.

Francis Hookham


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 125
Default Sorting

Many thanks Tom, you have prompted me to simplifying it to

Sub SortDataArea()
SortRow = 3
SortCol = 1
Cells(SortRow, SortCol).CurrentRegion.Sort _
Key1:=Cells(SortRow, SortCol), Order1:=xlAscending, Header:=xlYes
End Sub

so I do not have to actually select an ActiveCell.

That will make a great macro for future use - I don't think it can be cut
down any more.

Francis Hookham

"Tom Ogilvy" wrote in message
...
ActiveCell.CurrentRegion.Sort _
Key1:=ActiveCell.Offset(0,1), _
Order1:=xlAscending
Header:=xlYes

(change Header to xlNo if it has a header)

this will work if your data is separated from all other date by at least
one
blank row/column in all directions and you want to use the column to the
right of the activecell as the sort key.

--
Regards,
Tom Ogilvy

"Francis Hookham" wrote:

With a cell selected in a bold header row, clcking the 'Sort Ascending'
button on the toolbar does exactly what I want.

It would be great to be able to put something this into a macro

Cells(2, 3). Sort, Order1:=xlAscending

but if I record a particular situation I get

ActiveCell.Offset(-1, 0).Range("A1:D75").Sort
Key1:=ActiveCell.Offset(-1, 1). _
Range("A1"), Order1:=xlAscending, Header:=xlGuess,
OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortNormal

which is specific in that it is picking up the particular range which
will
change in the sheet I am wanting to sort.

Any suggestions for a universal sorting macro - ok xlAscending and the
other
bits can be set.

Francis Hookham





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
Sorting Values Without Sorting Formulas SBX Excel Discussion (Misc queries) 2 April 12th 09 11:17 PM
Automatic sorting (giving max and min) based on custom sorting lis Joe Lewis[_2_] Excel Worksheet Functions 4 November 23rd 08 05:12 AM
Sorting VLookup vs Sorting SumProduct Lauren Excel Discussion (Misc queries) 1 August 21st 07 12:19 AM
Sorting: Sorting by the First Character dzuy Excel Discussion (Misc queries) 2 June 22nd 06 08:27 PM
Sorting ListBox results or transposing ListBox values to other cells for sorting Rob[_8_] Excel Programming 1 July 9th 03 04:35 AM


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

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"