How to use the VBA CSNG Function (Syntax + Example)

HomeVBA Functions LIST (Category Wise)How to use the VBA CSNG Function (Syntax + Example)

The VBA CSNG function is listed under the data type conversion category of VBA functions. When you use it in a VBA code, it converts an expression into a single data type. Actually it converts a value into a single-precision floating-point number. You can read more this format from here.

Syntax

CSng(Expression)

Arguments

  • Expression: The value which you want to convert to a single data type.

Example

To practically understand how to use VBA CSNG function, you need to go through the below example where we have written a vba code by using it:

Sub example_CSNG()
MsgBox CSng("699.9999999")
End Sub

In the above example, we have used the value 699.9999999 and then we have used the CSNG function to convert that value into a single data type and it has returned 700 in the result.

VBA MSGBOX

Notes

  • If the value specified is a value other than a number or a string which can’t be recognized as a number, VBA will return the run-time 13 error.

Related Functions

CBOOL | CBYTE | CCUR | CDATE | CDBL | CDEC | CHR | CINT | CLNG | CSTR | CVAR | FORMATCURRENCY | FORMATDATETIME | FORMATNUMBER | FORMATPERCENT | HEX | OCT | STR | VAL