| Be the first user to complete this post  | Add to List | 
Excel-VBA : Math Functions – VAL()
Excel-VBA : Math Functions – VAL()
Description: The VAL function in MS excel returns the number found in the input string
NOTE: This function stops reading the string when it finds first non-numeric charater. Blank spaces are not considered as non-numeric character.
Format:
VBA Function : VAL(string)
Arguments:
- Number
- Mandatory
- Type: String
- String from which the number needs to be extracted.
 
Cases:
| 10 Sumit | 10 | 
| 20 Jain | 20 | 
| 10 20 Sumit Jain | 1020 | 
| 44.2 - I m double | 44.2 | 
| No Number | 0 | 
Example:
Function getVAL()
    val1 = "10 Sumit"
    val2 = "20 Jain"
    val3 = "10 20 Sumit Jain"
    val4 = "No Number"
    strResult = "The VAL of String " & val1 & " is " & Val(val1) & vbCrLf
    strResult = strResult & "The VAL of String " & val2 & " is " & Val(val2) & vbCrLf
    strResult = strResult & "The VAL of String " & val3 & " is " & Val(val3) & vbCrLf
    strResult = strResult & "The VAL of String " & val4 & " is " & Val(val4)
    MsgBox strResult
End Function

 
    