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.The VAL function is a built-in function in Excel that is categorized as a String/Text Function. It can be used as a VBA function (VBA) in Excel. As a VBA function, you can use this function in macro code that is entered through the Microsoft Visual Basic Editor.
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.
Returns
The VAL function returns a numeric value.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")For example:
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
Dim LNumber As DoubleIn this example, the variable called LNumber would now contain the value of 56.2
LNumber = Val("56.2 tables")
ليست هناك تعليقات:
إرسال تعليق