ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro to sort - Issue (https://www.excelbanter.com/excel-discussion-misc-queries/218406-macro-sort-issue.html)

Lise

Macro to sort - Issue
 
Hi

I have set-up a macro to sort the worksheet as a whole alphabetically on
Column 1 when CTL - p is entered which most time works well - however I have
one sheet where it continually includes he header row in the search instead
of leaving it at the top as it does for the other work sheets - what am I
doing wrong please??
--
Thanks

Lise

Otto Moehrbach[_2_]

Macro to sort - Issue
 
Please post your code. HTH Otto
"Lise" wrote in message
...
Hi

I have set-up a macro to sort the worksheet as a whole alphabetically on
Column 1 when CTL - p is entered which most time works well - however I
have
one sheet where it continually includes he header row in the search
instead
of leaving it at the top as it does for the other work sheets - what am I
doing wrong please??
--
Thanks

Lise




Lise

Macro to sort - Issue
 
Hi Otto

I hope thi sis what you're after :-)

Sub Sort()
'
' Sort Macro
' Macro recorded 29/01/2009 by seniorl
'
' Keyboard Shortcut: Ctrl+p
'
Cells.Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=2, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveWorkbook.Save
End Sub
--
Thanks

Lise


"Otto Moehrbach" wrote:

Please post your code. HTH Otto
"Lise" wrote in message
...
Hi

I have set-up a macro to sort the worksheet as a whole alphabetically on
Column 1 when CTL - p is entered which most time works well - however I
have
one sheet where it continually includes he header row in the search
instead
of leaving it at the top as it does for the other work sheets - what am I
doing wrong please??
--
Thanks

Lise





Gord Dibben

Macro to sort - Issue
 
Excel usually "guesses" correctly if the header row is formatted differently
or has a different data type than the rows below.

You can change Header:=xlGuess to Header:=xlYes

or just bold A1............safer changing the code, then you take it out of
Excel's hands.

BTW................Cells.Select selects all cells on the sheet which slows
things down

Maybe ActiveSheet.UsedRange.Select


Gord Dibben MS Excel MVP

On Thu, 29 Jan 2009 14:25:01 -0800, Lise
wrote:

Hi Otto

I hope thi sis what you're after :-)

Sub Sort()
'
' Sort Macro
' Macro recorded 29/01/2009 by seniorl
'
' Keyboard Shortcut: Ctrl+p
'
Cells.Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=2, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveWorkbook.Save
End Sub



Lise

Macro to sort - Issue
 
Fantastic Gord - thanks so much.
--
Thanks

Lise


"Gord Dibben" wrote:

Excel usually "guesses" correctly if the header row is formatted differently
or has a different data type than the rows below.

You can change Header:=xlGuess to Header:=xlYes

or just bold A1............safer changing the code, then you take it out of
Excel's hands.

BTW................Cells.Select selects all cells on the sheet which slows
things down

Maybe ActiveSheet.UsedRange.Select


Gord Dibben MS Excel MVP

On Thu, 29 Jan 2009 14:25:01 -0800, Lise
wrote:

Hi Otto

I hope thi sis what you're after :-)

Sub Sort()
'
' Sort Macro
' Macro recorded 29/01/2009 by seniorl
'
' Keyboard Shortcut: Ctrl+p
'
Cells.Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=2, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveWorkbook.Save
End Sub





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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com