Apply Names in Excel is bugged?

4

1

I see people had this problem 10 year ago and it's still not fixed. Or maybe I just don't know how to use this feature.
enter image description here

In my sheet I have these named ranges:
A1 - "name1"
B1 - "name2"
C1 - "name3"

In some other 3 cells I have these formulas:

=A1
=A1+B1
=COUNT(A1:C1)

After running Apply Names... I expect to have this:

=name1
=name1+name2
=COUNT(name1:name3)

I never get that no matter what options I choose. Moreover, usually my formulas become completely ruined...

=name1
=name1
=name1

How could I get the result I need?
I am knowledgeable in VBA, so I tried to design a solution to this problem using VBA, but the code was not working either.

I'm using Excel 2013, 32-bit (MS Office Professional Plus). OS - Windows 7 Enterprise, 64-bit.

ZygD

Posted 2015-05-25T21:55:52.170

Reputation: 911

1I'm getting the same problem as you. You're not alone! – Andi Mohr – 2015-12-03T13:03:06.197

What versions of excel are you using? OP and @AndiMohr – Raystafarian – 2015-12-03T13:07:05.250

@Raystafarian I'm on Excel 2013 (Office Pro Plus 2013) on 64bit Windows 7 Pro. – Andi Mohr – 2015-12-03T13:09:12.787

I added to my answer I cannot reproduce with excel 2007 on windows 7, this is what I have at work. I'll try to vpn home.. – Raystafarian – 2015-12-03T13:10:43.887

2All right, I used 2013 w7 and added it to my answer. Same issue. 10 years ago was excel 2003 though.. @AndiMohr – Raystafarian – 2015-12-03T13:17:37.017

1

It seems a number have people have flagged this as a bug in Excel 2010 & 2013. One suggestion I've found is to install the freeware Name Manager tool from Jan Karel Pieterse.

– Andi Mohr – 2015-12-03T15:22:21.223

1

@AndiMohr thank's for the link to the MS Answers site. It's also here with indication it was posted to the partners site, but I don't have access to that. We may just have to accept it

– Raystafarian – 2015-12-03T17:40:23.890

1I added excel 2016 to my answer - very strange. @AndiMohr – Raystafarian – 2015-12-04T10:07:45.023

@ZygD This is the first time I'd even noticed Apply Names was a thing. Whenever I've had to swap cell references for named ranges like this in the past, I've used Find and Replace. Is there a reason this wouldn't work for you? – Andi Mohr – 2015-12-04T11:46:23.667

1Added another answer with a VBA solution. It has some limitations, but it should work. @AndiMohr – Raystafarian – 2015-12-04T14:26:56.420

1

In my macro solution I link to my question over on code review, it seems the best option for a work-around would probably be regex. I'm not a regex guru by any means. I think Excellll has decent experience with regex (and excel), but most likely you'll find a better workaround over on stack overflow.

– Raystafarian – 2015-12-06T10:14:18.303

Answers

2

I can't replicate this (with my version of excel on Windows 7) -

enter image description here

If I define your names and then create formulas

enter image description here

Then apply names

enter image description here

I get the desired result -

enter image description here

How are you defining the names? I select the cell then click on its title to the left of the formula bar and type in the name.

enter image description here


With yours -

enter image description here

apply names -

enter image description here

As shown here

enter image description here


No change without "showing formulas" -

enter image description here

apply names

enter image description here


Okay, here we go. Office 2013, windows 7

enter image description here

apply names

enter image description here

Looks like a replicated failure.


Okay, let's try Excel 2016 on OSX Yosemite

Let's define our names and formulas -

enter image description here

Good, good, let's apply our names

enter image description here

What? Alert Formula is too long

enter image description here

Now it selected my count and.. what? Alert Microsoft Excel cannot find any references to replace

enter image description here

And it's a.. partial failure?

enter image description here

Okay then, let's do this manually -

enter image description here

Strange, it doesn't highlight the range, just the two cells?

But it works?

enter image description here

Just for comparison, a regular count highlights the range -

enter image description here

Raystafarian

Posted 2015-05-25T21:55:52.170

Reputation: 20 384

Try it with A1, B1 and C1 like in my example. – ZygD – 2015-12-03T12:47:37.393

@ZygD I added your example, cannot reproduce. – Raystafarian – 2015-12-03T12:51:57.003

I define names the same way as you do. I noticed you do it with Show Formulas enabled, and I tried the same thinking that this is how I can resolve my issue. But unfortunately I still have the same situation - =name1 in all of the 3 cells which had formulas before Apply Names was used. – ZygD – 2015-12-03T12:55:41.447

I also tried using Apply Names with different set of Options which appear after clicking that button on the dialog. No success. How else can I help you to reproduce the issue? – ZygD – 2015-12-03T13:00:53.253

I did it without showing formulas and had no change. Are you sure your names are still defined after you apply them? – Raystafarian – 2015-12-03T13:03:30.387

Yes - names are still defined after Apply Names is used. I checked it both, on the box on left of the formula bar and in Name Manager. – ZygD – 2015-12-03T13:06:58.493

1Add your version of excel and OS to your question, maybe that matters – Raystafarian – 2015-12-03T13:11:40.220

1Yeah, I added my 2013 attempt and can replicate. – Raystafarian – 2015-12-03T13:18:58.410

1Added 2016 and.. it doesn't have the same problem, but it doesn't work either. – Raystafarian – 2015-12-04T10:09:26.623

That is just amazing... the newest version of Office... :( Btw, it's cool you have the ability to test things on different versions of Office, including 2016 ;) – ZygD – 2015-12-04T17:53:30.803

1

As was pointed out in code review, this will cause problems if, for instance, it's looking for "A1" and finds "A10" etc.

Okay, here's my attempt at a work-around. With this, your formulas must use absolute references all the time. It works on named ranges larger than 1 cell.

Please note that I'm searching usedrange - but you can narrow that down as you like by resetting srchRng.

Option Explicit
Sub FixNames()

Dim ClctNames As Variant
Set ClctNames = ActiveWorkbook.Names

Dim rngName As String
Dim rngNameLoc As String
Dim strFrmla As String

Dim c As Range
Dim n As Integer

'Define as needed
Dim srchRng As Range
Set srchRng = ActiveSheet.UsedRange

'For each name (n) in the collection
For n = 1 To ClctNames.Count

    'I'm storing the Named Range's name and address as strings to use below
    rngName = ClctNames(n).Name
    rngNameLoc = ClctNames(n).RefersToRange.Address

    '--Should I break this out into a function? If so, at what point?
    For Each c In srchRng
        'We only want to test cells with formulas
        If c.HasFormula = True Then
           'We have to check if the cell contains the current named range's address
           If InStr(1, c.Formula, rngNameLoc, vbTextCompare) <> 0 Then
              'Since these are perfect matches, no need to look for length or location, just replace
              strFrmla = Replace(c.Formula, rngNameLoc, rngName)
              c.Formula = strFrmla
           End If
        End If
    Next
Next

'No error handling should be needed

End Sub

You need to use absolute references because when I pull the named range's RefersToRange.Address it's returning a range object - not a range, so I'm setting it as a string. I guess you could write a function that removes the $ absolute references if you'd like.

that was a fun one

Raystafarian

Posted 2015-05-25T21:55:52.170

Reputation: 20 384

Thanks. I value your input a lot. I have read both posts (here and in Code Review). I like that you uploaded your code there and those guys gave very precious comments (upvoted the question and the answers in CR). I have analysed your code too. To my mind, the limitations of the code are too big, so I would not choose to use it on some important workbook. As you note yourself - the case of A1 and A10. – ZygD – 2015-12-06T16:36:24.383

1

Say we start with:

enter image description here

and we already have assigned Names to A2 and B2. In the Formulas Tab, pull-down:

Define Name > Apply Names...

enter image description here

Make sure we hi-light both names and touch OK

and we get:

enter image description here

and so the Names get applied!

Gary's Student

Posted 2015-05-25T21:55:52.170

Reputation: 15 540

I tried that with your data and names. Yes it works. But please try it with my data/names if you want to see some interesting stuff going on. – ZygD – 2015-05-26T11:59:46.367

I'll give it a try later.................I will try to build a macro that can process formulas in a block of cells.................. – Gary's Student – 2015-05-26T12:03:10.617

Have you tried it? Aren't you convinced that the behaviour is bugged? – ZygD – 2015-06-20T12:02:11.327

@ZygD .....I have tried it...........I can't get it to work reliably............I am still looking at the macro approach... – Gary's Student – 2015-06-20T12:06:35.623