0

I'm trying to use the following formula in a cell where Name is a defined cell. When I run 'MsgBox Name.Address' it gives me the correct cell, but when I run the formula I get

run-time error '1004'

Worksheets("E'ee Details").Range("N1").FormulaR1C1 = "=VLOOKUP(" & Name.Address & ",EmployeeBank!C[-13]:C[-10],4,FALSE)"

The code also correctly places in the value of the variable if I remove .address

Worksheets("E'ee Details").Range("N1").FormulaR1C1 = "=VLOOKUP(" & Name & ",EmployeeBank!C[-13]:C[-10],4,FALSE)"

This gives me =VLOOKUP(J Bob,EmployeeBank!A:D,4,FALSE) in the cell. This would work but I can't put quotation marks around the name as these are already in place in the vba code. I tried doing multiple quotation marks and also char(34) but couldn't get it to work.

1
  • For future reference, Find (with Offset) is a much better alternative in VBA Commented Jan 4, 2018 at 13:18

2 Answers 2

0

You need to use an additional double quotation.

Sign up to request clarification or add additional context in comments.

Comments

0

Sorted it, I was putting in the wrong number of quotation marks!!!!

Worksheets("EeeDetails").Range("N1").FormulaR1C1 = "=vlookup(""" & NewName & """,EmployeeBank!C[-13]:C[-10],4,FALSE)"

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.