2

I am having 2 workbooks (Lookup and Destination) and trying to retrieve values from a defined name range in the Lookup workbook.

 ......
 Set rng = Range(Cells(15, 3), Cells(863, 12)) 'C15:L863
 wbkLookup.Names.Add Name:="LookupAreaDK", RefersTo:=rng
 ......
 colDest.Formula = "=VLOOKUP(" & colLookup.Address(False, False) & ", LookupAreaDK ,10,0)"

But I've got #NAME? as returned values. What is wrong with the syntax? Could anyone help? Thanks.

5
  • What is colLookup.Address(False, False)? And please check the ": they must be doubled in the macro like colDest.Formula = "=VLOOKUP(""" & colLookup.Address(False, False) & """, LookupAreaDK ,10,0)" Commented Feb 17, 2015 at 14:27
  • colLookup.Address(False, False) is currently "AG8". Could you tell me what you mean by "doubled in the macro"? Commented Feb 17, 2015 at 14:30
  • formula shown in Excel file with triple quotes of colLookup.Address is: VLOOKUP(" & colLookup.Address(False, False) & "; LookupAreaDK;10;0); while the double quotes give: =VLOOKUP("AG8"; LookupAreaDK;10;0) Commented Feb 17, 2015 at 14:37
  • Ah, I see now. No, you do not need to "escape" the quotation marks here, but please check that the colLookup.Address(False, False) is working. I tested with Range("E1").Formula = "=VLOOKUP(" & "D1" & ", LookupAreaDK ,3,0)", and it worked alright. Commented Feb 17, 2015 at 14:39
  • Thanks, I've got to work a bit more on the colLookup.Address(False, False) Commented Feb 17, 2015 at 14:47

1 Answer 1

1

So, you need to assign the address to the colLookup, or create another variable. Then, this works:

Dim colLookup As String
colLookup = Cells(1, 4).Address
colDest.Formula = "=VLOOKUP(" & colLookup & ", LookupAreaDK ,3,0)"
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.