PDA

View Full Version : Function Null to Zero shows errors


jennypretty
03-11-2010, 03:39 PM
Hello,

I modified a function Null To Zero that I found on the Internet to format a number. But it keeps showing syntax error right at Function.

Function NZ(tData)
If LEN(tData) = 0 Then
NZ = cdbl(0)
Else
On error resume next
tData = cdbl(tData)
If Not IsNumeric(tData) Then tData = 0
NZ = cdbl(tData)
End If

FormatNumber(NZ(total),2)

What did I do wrong?

Thanks.

Old Pedant
03-11-2010, 07:33 PM
It's a somewhat silly function, but it should work.

Maybe you are trying to put it into your code inside of some other function or sub???

Put it right at the very top or very bottom of your page.

Here's a simpler version:
Function NZ(num)
NZ = 0.0
On Error Resume Next
NZ = CDbl(num)
End Function

jennypretty
03-11-2010, 07:39 PM
It worked like charm.

Woh, thanks so much.