Avatar of Anthony Mellor
Anthony MellorFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

PC Excel range name scopes: how to edit these?

And how to paste them somewhere useful?

Also is there a way to identify names not in use?

I'd prefer on a Mac, but suspect that's not possible.

Edit: just to be clear I do not mean how to edit these one at a time, I mean in bulk. Even with VBA.

Anthony
Microsoft ExcelPCMicrosoft Office

Avatar of undefined
Last Comment
Anthony Mellor
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Are you familiar with Named Ranges? If not, select a range of cells and then go to Home->Formulas->Name Manager and click the New button. Then name it and click OK. With a slight modification to the generated Refers To formula the range will be dynamic.

What kind of bulk change do you envision making?
Avatar of Anthony Mellor

ASKER

Hi Martin, Yes I am familiar with named ranges.
I envisage PC Excel range name scopes and how to bulk edit these?
So for example:
User generated image
to set all these to "workbook" scope.

Regards Anthony

Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Try this:

Sub MakeGlobal()
Dim nr As Name
Dim strName As String
Dim strRefersTo As String

For Each nr In ActiveWorkbook.Names
    If Not nr.RefersToRange Is Nothing Then
        With nr.RefersToRange
            strName = Split(nr.Name, "!")(1)
            strRefersTo = nr.RefersToR1C1
            ' Remove the named range
            ActiveWorkbook.Names(nr.Name).Delete
            ' Add it back as global
            ActiveWorkbook.Names.Add Name:=strName, RefersToR1C1:=strRefersTo
        End With
    End If
Next nr
End Sub

Open in new window

Avatar of Anthony Mellor

ASKER

switching to PC .. actually I'll see if that runs on a mac..
Avatar of Anthony Mellor

ASKER

ok maybe not,  

User generated image

OFF TO PC WE GO
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Which line gives the error?
Avatar of Anthony Mellor

ASKER

GREAT, I don't know how to run a macro in pc excel
Avatar of Anthony Mellor

ASKER

User generated image
Avatar of Anthony Mellor

ASKER

is that the right macro? ok yes think it is
Avatar of Anthony Mellor

ASKER

same error on pc
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Change that line to
strName = nr.Name
Avatar of Anthony Mellor

ASKER

Will do.. need sleep first thanks:-)
Avatar of Anthony Mellor

ASKER

not yet:

User generated imageUser generated image


Sub MakeGlobal()
Dim nr As Name
Dim strName As String
Dim strRefersTo As String

For Each nr In ActiveWorkbook.Names
    If Not nr.RefersToRange Is Nothing Then
        With nr.RefersToRange
            strName = nr.Name
            strRefersTo = nr.RefersToR1C1
            ' Remove the named range
            ActiveWorkbook.Names(nr.Name).Delete
            ' Add it back as global
            ActiveWorkbook.Names.Add Name:=strName, RefersToR1C1:=strRefersTo
        End With
    End If
Next nr
End Sub




Avatar of Martin Liss
Martin Liss
Flag of United States of America image

It works for me in Excel 2010. Did you test it in Widows?
Avatar of Anthony Mellor

ASKER

no I'm on Mac
Avatar of Anthony Mellor

ASKER

doing that now
Avatar of Anthony Mellor

ASKER

same error on pc
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Can you attach the Windows Excel version of your workbook?
Avatar of Anthony Mellor

ASKER

it's the same file...?
Avatar of Anthony Mellor

ASKER

file herewith

except had to dlete it a sit's full or private data - 
Avatar of Anthony Mellor

ASKER

I'll see if i can do  quick delete... but it's a vast number of deletions
Avatar of Anthony Mellor

ASKER

Championship 2021 28MarV50_Bill_02-namesdeleted.xlsx

there ye go, that's from the windows pc thugh why ou might think it shoud be any different is a bit perplexing.
Avatar of Anthony Mellor

ASKER

funnily enough the deletion of names was greatly assisted by most of the entries being derived using Dynamic Arrays 
Avatar of Anthony Mellor

ASKER

can't stay awake any longer, thank for your help Martin, see you later, anthony
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Anthony Mellor

ASKER

Good morning Martin, delete which/what "ones that are not being used"? - Anthony

p.s. the file you requested is attached above.
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

I'm sorry but I don't know how to help you.

One problem you have is that there are named ranges like _FilterDatabase that have the same name but refer to different data, so I don't think it's possible to convert them to workbook scope.
Avatar of Anthony Mellor

ASKER

Ok that helps, thanks. I'll come back if I can add any more to this. 
Avatar of Anthony Mellor

ASKER

Penny drops: you mean delete the unused range names and try running it again. Noted, thanks.

Anthony
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

One thing that may be useful is the Filter button
User generated image
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

I’m glad I was able to help and thank you for the testimonial.

If you expand the “Full Biography" section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange Most Valuable Expert (MVE) 2015, 2017
              Experts Exchange Distinguished Expert in Excel 2018
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2020
              Experts Exchange Top Expert VBA 2018 to 2020
Avatar of Anthony Mellor

ASKER

Martin - you are very welcome and thanks for your time in assisting me. -
I try not to ask easy questions. Anthony
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

And I enjoy your offbeat sense of humor.
Avatar of Anthony Mellor

ASKER

Story of my life! :-)
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo