Returns the numbers contained in a string as a numeric value of the appropriate data type (Double).

stringThe text string (String).

* This function stops reading the string at the first character it can't recognize as part of a number.
* This function returns the first numerical component.
* 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. When different decimal separators are used, as in international applications, use CDbl instead to convert a string to a number.
* This function should not be used and the corresponding conversion functions, CStr(), CSng() etc should be used instead.
* 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

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") '=
Debug.Print Val("Jul 07, 2010") '=
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") '=
Debug.Print Val("sometext") '= 0
Debug.Print Val(1,2) '= 1
Debug.Print Val("&HFFFF") '= 1

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