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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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,214,593
Messages
6,120,435
Members
448,961
Latest member
nzskater

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