How to use IfError in Excel 2007 VBA ?
It would make more sense to me to just check the denominator cell for 0.
dim myVal as double
myVal = 99
With activesheet
if application.isnumber(.cells(1,1).value) then
if application.isnumber(.cells(1,2).value) then
if .cells(1,2).value < 0 then
myval = .cells(1,1).value / .cells(1,2).value
end if
end if
end if
.cells(1,3).value = myval
end with
Xavier wrote:
Hello,
I am trying to figure out how to use the IfError function with Excel 2007
VBA. I have built a simple spreadsheet to test division by zero error
handling. The following line either performs the division or throws an error
11 (division by 0) instead of returning 99.
ActiveSheet.Cells(1, 3) = WorksheetFunction.IfError((ActiveSheet.Cells(1, 1)
/ ActiveSheet.Cells(1, 2)), 99)
Any help would be appreciated.
Thanks,
Xavier
--
Dave Peterson
|