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
 

Some videos you may like

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

xenou

MrExcel MVP, Moderator
Joined
Mar 2, 2007
Messages
16,687
Office Version
  1. 2013
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)))"
 

Watch MrExcel Video

Forum statistics

Threads
1,108,492
Messages
5,523,260
Members
409,506
Latest member
reneekeane

This Week's Hot Topics

Top