VBA Force Header Row on Sort

Bench

Board Regular
Joined
Aug 27, 2009
Messages
134
Hi, is there a way to force a Header row on a sort in VBA

xlGuess is the default, are there any other options?

I can't seem to get the header row to stay no matter how i select the cells before sorting.

Thanks

Rich (BB code):
Intersect(Range("A:H"), ActiveSheet.UsedRange).Select
    Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range("E2") _
        , Order2:=xlAscending, Header:= _
        xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
        xlSortNormal
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Solved, sorry. I had tried xlYes previously and it didn't work, here is the amended code if anyone requires it for reference. I also changed the Range to start at row 1.

Thanks

Rich (BB code):
Intersect(Range("A:H"), ActiveSheet.UsedRange).Select
Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, Key2:=Range("E1") _
, Order2:=xlAscending, Header:= _
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
 
Last edited:
Upvote 0
Try

Rich (BB code):
Intersect(Range("A:H"), ActiveSheet.UsedRange).Offset(1).Sort Key1:=Range("B2"), _
        Order1:=xlAscending, Key2:=Range("E2") _
        , Order2:=xlAscending, Header:= _
        xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
        xlSortNormal
 
Upvote 0

Forum statistics

Threads
1,223,716
Messages
6,174,069
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top