Val Function

Use the Val function to convert a string that represents a number into numeric data type.


The string passed to the Val function is locale-independent. This means that commas are interpreted as thousands separators and a dot is used as the decimal separator.


    Val (Text As String)

Return value:



Text αŸ– αžαŸ’αžŸαŸ‚β€‹αž’αž€αŸ’αžŸαžšβ€‹αžŠαŸ‚αž›β€‹αžαŸ†αžŽαžΆαž„β€‹αž²αŸ’αž™β€‹αž…αŸ†αž“αž½αž“β€‹αž˜αž½αž™Β αŸ”

If only part of the string contains numbers, only the first appropriate characters of the string are converted. If the string does not contain any numbers then Val returns 0.

Error codes:

5 αž€αžΆαžšβ€‹αž αŸ…β€‹αž”αŸ‚αž”αž”αž‘β€‹αž˜αž·αž“β€‹αžαŸ’αžšαžΉαž˜αžαŸ’αžšαžΌαžœ


    Sub ExampleVal
        MsgBox Val("123.1") + 1 ' 124.1
        ' Below 123,1 is interpreted as 1231 since "," is the thousands separator
        MsgBox Val("123,1") + 1 ' 1232
        ' All numbers are considered until a non-numeric character is reached
        MsgBox Val("123.4A") ' 123.4
        ' The example below returns 0 (zero) since the string provided does not start with a number
        MsgBox Val("A123.123") ' 0
    End Sub

Please support us!