Thursday, August 11, 2016

How to use the VAL Function (VBA)

Description

The Microsoft Excel VAL function accepts a string as input and returns the numbers found in that string.

Syntax

The syntax for the VAL function in Microsoft Excel is:
Val( string )

Parameters or Arguments

string
A string expression that you wish to return the numbers found within.

Note

  • The VAL function will stop reading the string once it encounters the first non-numeric character. This does not include spaces.

Applies To

  • Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000

Type of Function

  • VBA function (VBA)

Example (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 to use the VAL function in Excel VBA code:
Val("10 Main Street")
Result: 10

Val("34 10 Main Street")
Result: 3410

Val("  34 10 Main Street")
Result: 3410

Val("  34 - 10 Main Street")
Result: 34

Val("075")
Result: 75
For example:
Dim LNumber As Double

LNumber = Val("56.2 tables")
In this example, the variable called LNumber would now contain the value of 56.2.

No comments:

Post a Comment