Debugging help insert formula into cell

desert_dweller5

New Member
Joined
Apr 8, 2011
Messages
30
Sub Rangeformula()
range("E3").Formula = "=IF(ISERROR(VLOOKUP(D3,$B$3:$C$19037,2,FALSE)),,VLOOKUP(D3,$B$3:$C$19037,2,FALSE)"
Range(e3:e20000).filldown
End Sub

This is my code. it wont run.

Run-time Error '1004': Application-defined or object-defined error.

*Frustrated*I'm simply trying to put the formula into the cell and fill down until there are no more entries in the column to the left.

it has to be the formula because when i put a value it works. for example:
Range("e3".Formula= 0

not sure why it wont take. maybe if i put the formula as a variable?
I dunno. any suggestions would be helpful.
thanks
Desert_dweller5
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi,

You need to a second close bracket at the end of your formula...

"=IF(ISERROR(VLOOKUP(D10,$B$3:$C$19037,2,FALSE)),,VLOOKUP(D10,$B$3:$C$19037,2,FALSE))"


igold
 
Upvote 0
As the 2nd poster pointed out the second ) was missing. Also unless you ALWAYS have 20000 rows to place the code on and you ALWAYS have 19037 rows of data in column C you could use the following.

Code:
Sub Rangeformula()

Dim lastRow As Long

lastRow = Range("D" & Rows.Count).End(xlUp).Row
   
Range("E3:E" & lastRow).Formula = "=IF(ISERROR(VLOOKUP(D3,B:C,2,FALSE)),,VLOOKUP(D3,B:C,2,FALSE))"

End Sub

This code will only place the formula in the areas it is needed, if you have 10 lines it places it in 10 lines, if you have 30000 lines it places it in 30000 lines and so on...
 
Upvote 0
Thanks for the prompt replies.
i have one more challenge. I need to have the cells that don't have a match or #N/A return as blank. when I use the double quotation marks the compiler is confused. is there a way to include these "" in the formula?
 
Upvote 0
I answered my own question by looking on the forum.
range("E3:E" & lastRow).Formula = "=IF(ISERROR(VLOOKUP(D3,B:C,2,FALSE)),"""",VLOOKUP(D3,B:C,2,FALSE))"

I had to put the double quotation marks in side of a second set of double quotation marks to let the compiler know that it was a character to pass along instead of code to compile. I'm not 100% sure this is correct but it seems to work. So I'm happy.

Thanks for your help guys!

see here for more details:
http://www.mrexcel.com/forum/excel-...within-formula-visual-basic-applications.html
 
Upvote 0
Great. I am glad you got it working. Thanks for the feedback!

igold
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

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