VBA Val function

Val Function Description

The VBA Val function converts a string containing a number to a number variable.


The syntax for the VAL function in Microsoft Excel is:

Val( string )


A string containing a number.

Other Notes

The Val function:

  • Trims whitespaces
  • Returns 0 if the first character in the string is not a digit
  • Converts only the first identified number within the provided string

Example usage

The Val function can be used in VBA code. Let’s look at some VBA Val function examples:

Val "A2A2"
'Result: 0

Val "2A2"
'Result: 2

Val "2 2"
'Result: 22

Val "2 1 2"
'Result: 212

Val "2 . 2"
'Result: 2,2