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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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
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
You are very welcome
And thank you for the feedback
Be happy and safe
 
Upvote 0

Forum statistics

Threads
1,224,975
Messages
6,182,109
Members
453,088
Latest member
Chaoxite

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