MS Excel: VAL Function (VBA)
The Microsoft Excel VAL function accepts a string as input and returns the numbers found in that string.
VAL Function (Syntax)
The syntax for the Microsoft Excel VAL function is:
Val( string )
string is a string expression.
- The VAL function will stop reading the string once it encounters the first non-numeric character. This does not include spaces.
The VAL function can be used in the following versions of Microsoft Excel:
- Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000
Type of Excel Function
The VAL function can be used in Microsoft Excel as:
- VBA function (VBA)
VAL Examples (as VBA Function)
The VAL function can only be used in VBA code in Microsoft Excel.
Let's look at some Excel VAL function examples and explore how you would use the VAL function in Excel VBA code:
|Val("10 Main Street")||would return 10|
|Val("34 10 Main Street")||would return 3410|
|Val(" 34 10 Main Street")||would return 3410|
|Val(" 34 - 10 Main Street")||would return 34|
|Val("075")||would return 75|
Dim LNumber As Double LNumber = Val("56.2 tables")
In this example, the variable called LNumber would now contain the value of 56.2.