Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to convert a string into a numerical value in Excel vba?
How to convert a string into a numerical value in Excel vba?
Second, the character values are converted into numerical data.

Val function can convert character data containing numeric values into Double (double precision) numeric data type, and its syntax is Val(string)?

Demo code:

Sub ShowFormatVal()

Dim num is Double and str is String.

Str = format (now "short time")

num = Val(str)

If the current time is 4: 3 pm1,the result shown in the following statement is: 16:3 1 16.

Debugging. Print string, number

End joint

App application

1, the character value cannot be used for four operations, and can only be used after being converted by the val function.

2. Octal number, 16 number, etc. Numbers that can be converted into 10, such as val (&; O77) (octal), val (&; HFF)( 16) is converted to decimal 63 and 255 respectively.