Listing Validating a Range for Appropriate Data

Function ReadCurrencyCell(rg As Range) As Currency Dim cValue As Currency cValue = 0

On Error GoTo ErrHandler

If IsEmpty(rg) Then GoTo ExitFunction

If Not IsNumeric(rg) Then GoTo ExitFunction cValue = rg.Value


ReadCurrencyCell = cValue Exit Function


ReadCurrencyCell = 0

End Function

You are guaranteed to get a numeric value back when you use the ReadCurrencyCell function. This eliminates the problem caused when a range of interest either contains text data or doesn't contain any value at all. In both of these cases, the procedure returns a zero.

0 0

Post a comment