turning formula into VBA code..please help

demodren

Board Regular
Joined
Aug 20, 2010
Messages
106
Hi, i am trying to incorporate the below formula into VBA but getting an error(application defined or object defined error).. Am i missing something here??

Any feedback is greatly appreciated!

Thanks so much

Dan

=LOOKUP(9^99,IF({1,0},0,LOOKUP(2,1/(P1=data!P$1:P$10001)/(E1=data!E$1:E$10001),data!K$1:K$10001)))

Code:
    Range("K1").Select
    ActiveCell.FormulaR1C1 = "=LOOKUP(9^99,IF({1,0},0,LOOKUP(2,1/(P1=data!P$1:P$10001)/(E1=data!E$1:E$10001),data!K$1:K$10001)))"
    Range("K1").Select
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,836
Office Version
  1. 2019
Platform
  1. Windows
Use:
ActiveCell.Formula

Not ActiveCell.FormulaR1C1

(or convert the A1 style formula to an R1C1 style formula ... if you turn on the macro recorder, hit F2 in the cell with the formula, then hit enter, then stop and examine the recorded code you'll see an R1C1 formula).

ξ
 

demodren

Board Regular
Joined
Aug 20, 2010
Messages
106
thanks so much.. that worked! I am now trying to drag this all the way down to whatever is the last row is in the sheet but getting error "AutoFill method of Range class failed" am I missing something in the code?


Code:
Sub test()
'
    Dim LastRow As Long
    LastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
 
    Range("K3").Select
    ActiveCell.Formula = "=LOOKUP(9^99,IF({1,0},0,LOOKUP(2,1/(P3=data!P$3:P$10001)/(E3=data!E$3:E$10001),data!K$3:K$10001)))"
    Range("K3").Select
    Selection.AutoFill Destination:=Range("K3" & LastRow)
End Sub
 

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Try

Code:
Range("K3:K" & LastRow).Formula = "=LOOKUP(9^99,IF({1,0},0,LOOKUP(2,1/(P3=data!P$3:P$10001)/(E3=data!E$3:E$10001),data!K$3:K$10001)))"
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,699
Messages
5,833,210
Members
430,197
Latest member
edeibold

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
Top