repeat for each named range

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

repeat for each named range

Post by VegasNath »

How can I adapt the following code to repeat for each named range "essbase" within the active workbook? The named range will be defined on some but not all worksheets in the workbook, preceded by the sheet name.

Code: Select all

Sub ESSBASE_RETRIEVE()

Application.Goto Reference:=Range("essbase")
Application.Run Macro:="EssMenuRetrieve"

End Sub

:wales: Nathan :uk:
There's no place like home.....

User avatar
HansV
Administrator
Posts: 78567
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: repeat for each named range

Post by HansV »

Try this:

Code: Select all

Dim nme As Name
For Each nme In ActiveWorkbook.Names
  If LCase(Right(nme.Name, 7)) = "essbase" Then
    Application.Goto Reference:=Range(nme.Name)
    Application.Run Macro:="EssMenuRetrieve"
  End If
Next nme
Best wishes,
Hans

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

Re: repeat for each named range

Post by VegasNath »

Cheers Hans. Works great!

Is there an easy way to define a named range accross several sheets?
:wales: Nathan :uk:
There's no place like home.....

User avatar
HansV
Administrator
Posts: 78567
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: repeat for each named range

Post by HansV »

Yes, but what would you do with it?
Best wishes,
Hans

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

Re: repeat for each named range

Post by VegasNath »

update it.

I need the same defined name accross several worksheets. The only way i know how is to type the name into the box, preceding it with the sheet name, which is a pain.
:wales: Nathan :uk:
There's no place like home.....

User avatar
HansV
Administrator
Posts: 78567
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: repeat for each named range

Post by HansV »

A named range across multiple sheets is not the same as multiple named ranges, each on one sheet. You will have to update the names one by one. Perhaps you can write a macro for this purpose.
Best wishes,
Hans

User avatar
Jan Karel Pieterse
Microsoft MVP
Posts: 656
Joined: 24 Jan 2010, 17:51
Status: Microsoft MVP
Location: Weert, The Netherlands

Re: repeat for each named range

Post by Jan Karel Pieterse »

You can download my Name Manager. It has a list option which lists all named ranges on a worksheet. You can then edit the named ranges on the sheet and afterwards have Name Manager pick up the changes.
Regards,

Jan Karel Pieterse
Excel MVP jkp-ads.com

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

Re: repeat for each named range

Post by VegasNath »

Thankyou, that is very useful.
:wales: Nathan :uk:
There's no place like home.....