VBA CSNG Function (Syntax + Example)

Last Updated: October 29, 2023
puneet-gogia-excel-champs

- Written by Puneet

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 about this format 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 the VBA CSNG function, you need to go through the below example where we have written a vba code by using it:

example-vba-csng-function
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.