Run time error 1004 - VBA Vlookup

marshy3300

Board Regular
Joined
Aug 17, 2014
Messages
59
Howdy,

I have this code

With Sheets("CDG Current")
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
With .Range("N2:N" & LastRow)
.Formula = _
"=IF(K2>VLOOKUP(RC4,'CDG MinMax'!R2C1:R6666C23,5,0),"""",IF(E2=E1,IF(SUMIF($E$1:$E1,E2,$N$1:$N1)+K2<0,M2,0),M2))"
'"=IF(K2>500,"""",IF(E2=E1,IF(SUMIF($E$1:$E1,E2,$N$1:$N1)+K2<0,M2,0),M2))"
.Value = .Value
End With
End With

And getting the runtime error on the vlookup line. Not sure why. if I change it to the >500 as below that it runs fine but i want it to lookup another sheet and grab that value.

Any help would be appreciated.

THANKS!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi marshy3300,

Forgetting about VBA for the moment, what is the actual worksheet formula you're trying to convert?

Robert
 
Upvote 0
Its basically a book that i dump in my overdue purchases to work out priorities to get made. On hand stock + on the water - allocated gives balance (k2).
N2 works out what can be made (overall minus on water) total whats allocated (same product can be listed multiple times) and if everything that balance is less than 500 it will spit out a quantity to make until that 500 total is reached.
That all works fine. What i amended was a lookup to change the 500 to a predetermined minimal stock holding on another page (which a seperate macro imports from a file) which spits the error.
 
Upvote 0
You didn't answer the question - what is the actual formula you want to replicate in VBA?
 
Upvote 0
Hi Trebor,

I replaced the RowColumns with actual cell references (A4) and seems to be working. Thanks for looking into the thread though!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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