How to define multiple names quickly?

Rnkhch

Well-known Member
Joined
Apr 28, 2018
Messages
528
Office Version
  1. 365
Platform
  1. Windows
Hello,

I need to define many names for chart series of the following type that allows for the chart to automatically adapt to expanding series:

name1=Excel!$E$36:INDEX(Excel!$E$36:$S$36,COUNT(Excel!$E$36:$S$36))

Is there any way to speed up this process, instead of defining them one by one in the name manager? I'm hoping I could perhaps write all my names in various rows along with their formulas in the column to the right and somehow import them into the name manager.

Alternatively, if this could be done through VBA, could someone suggest the code?

Thanks for any input!
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Depending on the worksheet layout, you can highlight the range for example A1:C10.
Got to the formula tab and select "create from selection", select what heading to use as the named range.

1654344697546.png
 
Upvote 0
I see, thank you, this is interesting. But I'm not sure how to put my exact syntax in the defined names. I tried putting the syntax in C2 as in the attached picture; is this the right way?




2022-06-04.png
 
Upvote 0
Give this a try:
Put your names in column A and your formula in column B.
Make sure there is nothing under your list in column A (so that xlup finds the bottom or your list)
I have assumed your first name starts on Row 2 change it if this is not the case.

If only works if any cell references in the formulas are absolute ie use $ sign.
I tried it with and without putting a single quote in front of the formula in column B and it seemed to work either way.

VBA Code:
Sub AddRngNames()

    Dim rng As Range, rCell As Range
    Dim nm As String
    Dim nmFormula As String
    
    Set rng = Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
    
    For Each rCell In rng

        ThisWorkbook.Names.Add Name:=rCell.Value, RefersTo:=rCell.Offset(0, 1).Formula
    
    Next rCell

End Sub
 
Upvote 0
Solution
Thank you so much. I'm gonna test this this week and may reach out if I need help with the exact procedure (I'm a newb at VBA). I'll update.
 
Upvote 0
Wow, this works so well!!! This is a miracle! It saved me so much time. Thank you again 🤗
 
Upvote 0

Forum statistics

Threads
1,214,388
Messages
6,119,227
Members
448,878
Latest member
Da9l87

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