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!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Welcome to the board.

Try

Range("B1:D21").CreateNames Top:=True, Left:=False, Bottom:=False, Right:=False
 
Upvote 0
How is make this script to run automaticaly once the data is added in new columns?
(Sorry for my bad English)
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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