Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

Excel-VBA : Math Functions – VAL()

Excel-VBA : Math Func­tions – VAL()

Descrip­tion: The VAL func­tion in MS excel returns the num­ber found in the input string

NOTE: This func­tion stops read­ing the string when it finds first non-numeric charater. Blank spaces are not con­sid­ered as non-numeric character.

For­mat:

VBA Func­tion : VAL(string)

Argu­ments:

  • Num­ber
    • Manda­tory
    • Type: String
    • String from which the num­ber needs to be extracted.

Cases:

10 Sumit 10
20 Jain 20
10 20 Sumit Jain 1020
44.2 — I m double 44.2
No Num­ber 0

Exam­ple:

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

VAL - VBA

VAL — VBA

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: