Using IfError function in VBA

CarolynS

Board Regular
Joined
Oct 27, 2015
Messages
56
I have the follwoing code to add in an IfError formula to column 8 of my worksheet

Code:
    FinalRow = Worksheets("CompsByCourse").Cells(Rows.Count, 1).End(xlUp).Row
    
    'On Error Resume Next
    
    For p = 5 To FinalRow
    
    Worksheets("CompsByCourse").Cells(p, 8) = Application.WorksheetFunction.IfError(Worksheets("CompsByCourse").Cells(p, 7) * Worksheets("CompsByCourse").Cells(p, 2), """0""")
    
    Next p
    'On Error GoTo 0

The formula is just multiplying 2 other columns but i use IfError as some of the data is non numerical and rather than causing an error to be displayed I would like a value of 0. This would work if i was typing the formula directly in to the worksheet, however, each time the code gets to the cells that don't contain numbers it errors. I could use On Error Resume Next (as shown in code above) but i would rather have not have blanks in the column.

It seems like there's no point in using the worksheet function IfError and rather I should be putting an "If IsError then" in to my code? I did try to do this but I didn't know how to fit it in around my For, Next loop and how to make it return 0 for cells that error?

Any help greatly appreciated

Thanks
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Instead of the above, try:
Code:
    FinalRow = Worksheets("CompsByCourse").Cells(Rows.Count, 1).End(xlUp).Row
    With Worksheets("CompsByCourse").Cells(5, 8).Resize(FinalRow - 4)
        .FormulaR1C1 = "=IFERROR(RC[-1]*RC[-6],0)"
        .FillDown
        .Value = .Value
    End With
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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