VBA - naming columns as ranges using row 1 labels

IanWallbridge

New Member
Joined
Jan 29, 2014
Messages
10
Hi all,


I've often used the following two lines of VBA to name column ranges based on text labels in the first row of a worksheet, and this has always been really useful when manipulating data.


Code:
Set rangeToName = Worksheets("Sheet1").Range("A:BZ")
rangeToName.CreateNames Top:=True, Left:=False, Bottom:=False, Right:=False


However, in my latest code I need to completely delete some columns, but have realised that - by default - the named ranges start in row 2 and don't include the top (labelled) row.


Can this code be tweaked with some sort of offset so that the label is included? I've tried setting the range in the first line to include row numbers, but this doesn't make any difference.


Hope someone can advise..
 

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.
If you want to delete the entire column use
Code:
   Range("aname").EntireColumn.Delete
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,974
Messages
6,175,739
Members
452,667
Latest member
vanessavalentino83

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