devxlogo

Val Doesn’t Work on Formatted Numbers

Val Doesn’t Work on Formatted Numbers

Beware of the Val() function. It doesn’t correctly recognize formatted numbers. Use CInt(), CDbl(), and soon instead:

 FormattedString = Format(1250, _        "General")            ' = "1,250.00"Debug.Print Val(FormattedString)        ' prints 1 !Debug.Print cDbl(FormattedString)        ' prints 1250

devx-admin

Share the Post: