We help IT Professionals succeed at work.
Get Started

VBA code that creates a series of multiple like-named local ranges

John Carney
John Carney asked
Last Modified: 2012-05-11
I have a series of 30 worksheets with names like "Wk 1", Wk 2", etc. up to "Wk 30". I have a global range named "ETD_Avail", defined as "='Wk 9'!$F$25:$F$41" I would like to duplicate the range as a local range on all 30 sheets. How would I do that with VBA?

The code below loops through the sheets but ends up with a global name referring to the last sheet. How do i write it so that each sheet gets its own local name?

Sub LocalNames()
For i = Worksheets("Wk 7").Index To Worksheets.Count
[k1] = ActiveSheet.Name
    Dim str As String
    str = "='" & ActiveSheet.Name & "'!R25C9:R40C9"
    ActiveWorkbook.Names.Add Name:="ETD_Avail2", RefersToR1C1:=str
End Sub

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE