How to name a range with a cell content

eoliann

New Member
Joined
Feb 18, 2015
Messages
5
Hello,
How to name a range like B1:B21 with B1 content, but in VB?
I need to rename also C2:C21 with C1 content and D2:D21 and so.
The lists name is used in Data Validation.
Thankyou!
 

Some videos you may like

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Welcome to the board.

Try

Range("B1:D21").CreateNames Top:=True, Left:=False, Bottom:=False, Right:=False
 

eoliann

New Member
Joined
Feb 18, 2015
Messages
5
How is make this script to run automaticaly once the data is added in new columns?
(Sorry for my bad English)
 

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061

ADVERTISEMENT

I think it would be best to run it manually as needed.

If you ran it automatically, how would it know the limit of the range?
Is it ready to be named after just 1 value is added to the column, or not till it's full to the end?

It could be adjusted to allow you to 'select' the range to name when you run it..

Code:
Sub test()
Dim MyRange As Range
Set MyRange = Application.InputBox("Select range to name", , , , , , , 8)
MyRange.CreateNames Top:=True, Left:=False, Bottom:=False, Right:=False
End Sub
 

eoliann

New Member
Joined
Feb 18, 2015
Messages
5
I found the solution. I added a button with code:
Private Sub Add_Info_Click()
Range("A2:D26").CreateNames Top:=True, Left:=False, Bottom:=False, Right:=False
Application.ScreenUpdating = True
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,832
Messages
5,598,360
Members
414,233
Latest member
WolverineNurse

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