Return to VBA Code Examples

VBA CSng Function

CSng Description

Converts a value to a single-precision number.

CSng Syntax

In the VBA Editor, you can type  “CSng(” to see the syntax for the CSng Function:

The CSng function contains an argument:

Expression: Any string or numeric expression.

Examples of Excel VBA CSng Function

Sub CSng_Example()
    Dim sngVal As Single
    sngVal = CSng("3.141592653589")
    MsgBox sngVal
End Sub

Running the above VBA code, it will display a message box as following.


VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as

Learn More!