Excel Names. VBA. RefersToR1C1 versus RefersTo. Where is the catch?

DEksel

Board Regular
Joined
Oct 5, 2019
Messages
52
I am adding (or overwriting the existing) name using VBA. Var str is String.
This one works:
Code:
    str = "=IFERROR(INDEX(Tickets!R5C2:R1024C13,MATCH(!RC4,Tickets!R5C4:R1024C4,0),!R3C2),0)"
    ActiveWorkbook.Names.Add Name:="DGrab", RefersToR1C1:=str
    ActiveWorkbook.Names("DGrab").Comment = "Nice one!"
The next one not.
Code:
    str = "=IFERROR(INDEX(Tickets!$B$5:$M$2048,MATCH(!$D5,Tickets!$D$5:$D$2048,0),!$B$3),0)"
    ActiveWorkbook.Names.Add Name:="DGrab", RefersTo:=str
    ActiveWorkbook.Names("DGrab").Comment = "Nice one!"
Why? I always hated R1C1 way...
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Looks like a bug to me.
Thanks m8! Nothing else I could find. I need to refresh that name all the time because each time when I kill some rows (and need to do it often or change their places), lookup range is changed too even it is fixed...
 
Upvote 0
If you delete rows, the ranges will always adjust accordingly. To avoid that you could use INDIRECT or perhaps INDEX instead.
 
Upvote 0
If you delete rows, the ranges will always adjust accordingly. To avoid that you could use INDIRECT or perhaps INDEX instead.
And be more concrete? Can you write the 'str' which will not change when I kill or move the ranges?
 
Upvote 0
You could use something like:

Code:
str = "=IFERROR(INDEX(INDIRECT(""Tickets!$B$5:$M$2048""),MATCH(INDIRECT(""RC4"",0),INDIRECT(""Tickets!$D$5:$D$2048""),0),INDIRECT(""R3C2"",0)),0)"
 
Upvote 0
You could use something like:

Code:
str = "=IFERROR(INDEX(INDIRECT(""Tickets!$B$5:$M$2048""),MATCH(INDIRECT(""RC4"",0),INDIRECT(""Tickets!$D$5:$D$2048""),0),INDIRECT(""R3C2"",0)),0)"
Sorry but that one simple does not work. Added without problems but "The Boy Does Nothing".

I have small procedure which I am running each time after killing or moving the rows... so I've added 'Create name' lines there and all is ok. I was just currious... If you really think that indirect will help (but have to work of course!), let's continue...

Thank you very much.
 
Upvote 0
It works for me. How are you using it?
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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