CSng VBA Function – How to Convert Data to Single Type

1. CSng VBA Function – Description

The CSng VBA function   returns a value with the Single data type  . It is a number between -3.402823e38 and 1.401298e45  . The Single data type is 4 bytes in memory. We usually use functions when we want our data to be more efficient. Using functions for numbers out of range or for non-numeric data will return an error. This function can be used to convert a floating point number written with a comma, not a period, to a floating point number recognized by VBA. The function also converts text to number.

2. VBA CSng Function – Syntax

CSng (Expression) As Single

Expression : Any number between -3.402823e38 and 1.401298e45 stored in any data type (including String).

Function return : Single / A floating point number ranging from -3.402823e38 to 1.401298e45.

3. VBA CSng function – Example

How to use CSng function in VBA Excel? Below are examples of using the CSng function in the VisualBasic Editor.

Example 1: Conversion to the Single type. CSng – function example.

Dim strValue As String
strValue = "123.12"
MsgBox CSng (strValue) / 100

Example 2: Converting to the Single type. VBA CSng – an example of a function.

Dim strValue As String
strValue = "1233.12"
Range ("A1") = CSng (strValue) * 5
Excel VBA Functions - CSng VBA function
Excel VBA Functions – CSng VBA function

4. VB CSng function – Additional information

  • The function used for numbers outside the range -3.402823e38 through 1.401298e45 will return an error.
  • This function can be used to convert a floating point number written with a comma, not a period, to a floating point number recognized by VBA.

5. CSng VisualBasic function – Where to use?

The function can be used in: Excel 2003, Excel 2007, Excel 2010, Excel 2013, Excel 2016.

The article is part of the VBA Excel function list. You can find a list of all VBA functions at this address:  VBA functions .

Leave a comment

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

%d bloggers like this: