0

The following formula works great when I directly add it in excel, but when I add it to VBA I get a Run Time error: Application-defined or object-defined error.

This is the Formula I am inserting into the macro:

ActiveCell.FormulaR1C1 = "=VLOOKUP([[#This Row],[MATERIAL]],material!A$3:D$114,3)"

What am I doing wrong?

TableName = ActiveSheet.Previous.Name & "_Spider"

Range(TableName & "[RAWMATERIAL LENGTH]").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP([[#This Row],[MATERIAL]],material!A$3:D$114,3)"
2
  • Try using the macro recorder, I think that your syntax around [[#This Row],[MATERIAL]] is incorrect. The macro recorder should provide a suitable R1C1 formula to work with. Commented Nov 4, 2013 at 21:57
  • Use Debug.Print to output the formula to the Immediate pane in the VBE, and check it's what you're expecting. Copy/paste from there to the worksheet and check it's accepted. As @SamWard notes, your formula format looks wrong. Commented Nov 4, 2013 at 22:11

1 Answer 1

2

I believe the issue is that when you set the formula with .FormulaR1C1 (msdn reference), you have to refer to cells by row and column numbers (for example =SQRT(R2C5)). You should try using .Formula (msdn reference) instead.

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.