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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
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).

ξ
 
Upvote 0
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
 
Upvote 0
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)))"
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,547
Members
452,925
Latest member
duyvmex

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