VBA question

tispivey

New Member
Joined
Mar 10, 2022
Messages
30
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I have a possibly stupid question. I can get a formula to work for what I want, but when I attempt to add it to a macro that I have, I get an error.

The formula is =IFERROR(IF(VALUE(N2)=$BD$1," ",VLOOKUP(VALUE(LEFT(N2,3)),BD:BE,2,0)),"")

Which essentially looks up a code, compares it to a list I have in the spreadsheet, then returns something from another list, then if there is an error, it returns nothing. This works in the spreadsheet, but when I attempt to put that same formula in the VBA code I have, it breaks.

This is the code that works, before the IFERROR:

Range("ag" & I).Formula = "=IF(VALUE(n" & I & ")=$bd$1,"" "",VLOOKUP(VALUE(LEFT(n" & I & ",3)),BD:BE,2,0))"

But as soon as I attempt to add the Iferror, it breaks. Is there a different way to add iferror to a code in VBA?

This is for work, and has customer info, so I am not sure how much I can put in here, but if it is needed, I can try.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
What was the formula that didn't work & in what way didn't it work?
 
Upvote 0
This works in VBA:

Range("ag" & I).Formula = "=IF(VALUE(n" & I & ")=$bd$1,"" "",VLOOKUP(VALUE(LEFT(n" & I & ",3)),BD:BE,2,0))"

But, what I want to do is like an IFERROR then leave a blank cell.

Is there a different want to put this in VBA than in excel?
 
Upvote 0
That is not what I asked for & you didn't answer my other question either. ;)
Sorry, missed that.

Range("ag" & I).Formula = "=IFERROR(IF(VALUE(n" & I & ")=$bd$1,"" "",VLOOKUP(VALUE(LEFT(n" & I & ",3)),BD:BE,2,0)),"")"

This code works when I manually put it in Excel, but wont in VBA. The error I get is: Run-time error '1004': Application-defined or object-defined error
 
Upvote 0
Ok, thanks for that, you need to double-up on the quotes for the error value.
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,526
Messages
6,125,328
Members
449,218
Latest member
Excel Master

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