VAL

VAL(string)

Returns the first number contained in a string (Double).


stringThe text string (String).

REMARKS
* CDBL, CINT, CLNG and CSNG should be used instead.
* This function is provided for backwards compatibility and should not be used.
* This function stops reading the string at the first character it can't recognize as part of a number.
* Symbols and characters that are often considered parts of numeric values, such as dollar signs and commas, are not recognised.
* However, the function recognizes the radix prefixes &O (for octal) and &H (for hexadecimal).
* Blanks, tabs, and linefeed characters are stripped from the argument.
* This function only recognizes the period (.) as a valid decimal separator.
* This function will return an error if it finds any Data Type Characters.
* You can use the DATESERIAL function to return the date given a year, month and day.
* The equivalent .NET function is Microsoft.VisualBasic.Conversion.Val
* For the Microsoft documentation refer to learn.microsoft.com

Debug.Print Val("02/04/2010")                '= 2  
Debug.Print Val("16/04/2012") '= 16
Debug.Print Val(VBA.DateSerial(2012,7,14)) '= 14
Debug.Print Val("14/07/2012") '= 14
Debug.Print Val("1050") '= 1050
Debug.Print Val("130.75") '= 130.75
Debug.Print Val("54.321") '= 54.321
Debug.Print Val("Jul 07, 2010") '= 0
Debug.Print Val("50 Park Lane") '= 50
Debug.Print Val("1320 then some text") '= 1320
Debug.Print Val("£13.5") '= 0
Debug.Print Val("False") '= 0
Debug.Print Val("sometext") '= 0
Debug.Print Val("1,2") '= 1
Debug.Print Val("&HFFFF") '= 1

Debug.Print Val("10%") '= 10
Debug.Print Val("10.5%") '= error

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top