first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

Notes on the Val() Function

Use the Val() function if you are contemplating using LTrim$() and CDbl() on a string literal. You only want the leftmost characters from this string. You want to separate the numeric values from the non-numeric values from this string---and the numeric values are leftmost. And, most importantly, you want to convert this value to data type Double.

Without Val() you would have to use LTrim$() to find the leftmost numeric characters and then CDbl() to convert them. Please recall that CDbl() will return a Type Mismatch error in the following:

VBA.CDbl("123Text")

however,

VBA.Val("123Text") = 123

also consider this a warning:

VBA.Val("1,234") = 1
mod date: 1999-05-19T03:02:41.000Z