Sort column excluding header

riley454

Board Regular
Joined
Apr 21, 2010
Messages
52
Office Version
  1. 2010
Platform
  1. Windows
I have a column (with a title in row 1) containing a list that I want to sort alphabetically prior to performing other actions. Using the following code, everything is sorted alphabetically as expected but unfortunately includes the header/title from row 1.

How can I perform this simple sort function in VBA without including the title/header as part of the sorting?

As a side note the number of rows of data in column GZ may change so I'm not able to state a simple Range(GZx : GZy) in the selection

VBA Code:
Set srtR = Sheets(sht).Range("GZ:GZ")
srtR.Sort Key1:=Range("GZ:GZ"), Order1:=xlAscending
 
Last edited:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

mohadin

Well-known Member
Joined
Mar 22, 2015
Messages
1,656
Office Version
  1. 2013
Platform
  1. Windows
VBA Code:
Sub test()
    Set srtR = Sheets("sht").Range("GZ2:GZ" & Cells(Rows.Count, "GZ").End(xlUp).Row)
    srtR.Sort Key1:=Range("GZ:GZ"), Order1:=xlAscending
End Sub
 
Upvote 0
Solution

riley454

Board Regular
Joined
Apr 21, 2010
Messages
52
Office Version
  1. 2010
Platform
  1. Windows
Thanks mohadin that's exactly what I needed. I was sure it would be something simple but it's getting late and I was over thinking it
 
Upvote 0

mohadin

Well-known Member
Joined
Mar 22, 2015
Messages
1,656
Office Version
  1. 2013
Platform
  1. Windows
You are very welcome
And thank you for the feedback
Be happy and safe
 
Upvote 0

Forum statistics

Threads
1,186,516
Messages
5,958,300
Members
438,348
Latest member
JS050

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
Top