0

I trying to add named range with VBA

Nname = "FindMe"
Formulas = "Vlookup(" & Chr(34) & Nname & Chr(34) & ";Translations!$A:$C;2;False)"
ActiveWorkbook.Names.Add Name:=Nname, RefersToR1C1:=Formulas

But i get

Vlookup(""FindMe"";Translations!$A:$C;2;False)

Instead of

Vlookup("FindMe";Translations!$A:$C;2;False)

Why Excel put double qoutes? How to Get string which i want?

Vlookup("FindMe";Translations!$A:$C;2;False)

1
  • as it looks right now to me, you can only set a range as it is as RefersTo**, formulas always pop up an error (at least for me) Commented Nov 23, 2015 at 21:54

1 Answer 1

2

The string assigned to Formulas is missing an '=' at the beginning of the string. Thus, the name is being assigned a string constant instead of a formula. When you look in Name Manager dialog, you will that name FindMe refers to ="Vlookup(""FindMe"";Translations!$A:$C;2;False)". Note that two double quotes represents a single quote in a string constant.

If you add a '=' to the beginning of the string, then name will be assigned a formula. Also, the formula is using A1 notation but the VBA code is using RefersToR1C1. This will cause a formula parsing error. Either change the formula to R1C1 notation or change the VBA code to use RefersTo. For example...

Nname = "FindMe"
Formulas = "=Vlookup(" & Chr(34) & Nname & Chr(34) & ",Translations!$A:$C,2,False)"
ActiveWorkbook.Names.Add Name:=Nname, RefersTo:=Formulas
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.