I have the following line in Excel VBA:
ActiveCell.Offset(r, 1).Value = IIf(rs2.Fields("SalesRelatedCallsQTD").Value = 0, "--", FormatPercent(rs2.Fields("SoldCallsQTD").Value / rs2.Fields("SalesRelatedCallsQTD").Value, 2))
When I run the macro in Excel I get a "Run-time error '6': Overflow" error.
I know there is the possibility of getting a 0 value in the denominator hence the use of IIf to check for this. Is it possible that Excel is still trying to calculate the
FormatPercent(rs2.Fields("SoldCallsQTD").Value / rs2.Fields("SalesRelatedCallsQTD").Value, 2)
and throwing the error? If so how do I get around this or is there something else wrong with this code?
EDIT
When I add a watch here are the values I get:
rs2.Fields("SalesRelatedCallsQTD").Value : 0 : Variant/Long
rs2.Fields("SoldCallsQTD").Value : 0 : Variant/Long
rs2.Fields("SoldCallsQTD").Value / rs2.Fields("SalesRelatedCallsQTD").Value : <Overflow> : Variant/Integer
Nullvalues here and there ? THe best way is to get step by step mode and see what your values look like, and/or include a fewdebug.Printin your code.ActiveCell(its address),r,rs2.Fields("SoldCallsQTD").Valueandrs2.Fields("SalesRelatedCallsQTD").Valuewhen you get the error?