variables in .formula vs .formular1c1

jkicker

Board Regular
Joined
Jun 7, 2018
Messages
79
Trying to sub a variable into vlookup for the table array.
This works:

Code:
Sub vl()
' temporary fix for summer teach

Dim vl1 As Range
Dim vl2 As Range
Dim vl1a As Range

    Set vl1 = Range("A:A").Find("C.I.")

    Set vl2 = Range("B:B").Find("17200")

    Set vl1a = Range(vl1, vl2)

    MsgBox vl1a.Address

    ActiveCell.Formula = "=VLOOKUP(G5," & vl1a.Address & ",2)*H5"


End Sub

This doesn't:

Code:
Sub vl()
' temporary fix for summer teach

Dim vl1 As Range
Dim vl2 As Range
Dim vl1a As Range

    Set vl1 = Range("A:A").Find("C.I.")

    Set vl2 = Range("B:B").Find("17200")

    Set vl1a = Range(vl1, vl2)

    MsgBox vl1a.Address

    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-2]," & vl1a.Address & ",2)*RC[-1]"

End Sub

"Application-defined or object-defined error"
I guess that means that's not how you call a variable in this format. I need to use the second version, how do you do it?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Glad to help & thanks for the feedback.
Not sure what you mean by "Internet Points", but if you are referring to a ranking or reputation system, then we don't have one here.
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,545
Members
449,089
Latest member
davidcom

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