What is CSng Function in Excel VBA

The SCng function is a VBA function that converts any data type to a single-precision floating-point number ("given that it is a number"). I mostly use CSng function to convert text formatted numbers into actual numbers.

Syntax of CSng function:

CSng(expression)

expression: It can be any expression. A text or a method that returns some values.

Here's one Example:

Convert Text to Number using VBA

Sub TextToNumber()
 stri="5.5"
 stri = CSng(stri)
 debug.print stri
End Sub

The above VBA snippet will convert the stri into a number. A similar function CDec. The CDec function converts given expression into a decimal number.

Another Example of  CSng function:

Change Text to Number Using VBA

That's it. This is what CSng function does. I hope it was helpful. If you have any other query regarding this function or any other VBA related query, ask in the comments section belo2.

Related Articles:

How to get Text & Number in Reverse through VBA in Microsoft Excel | To reverse number and text we use loops and mid function in VBA. 1234 will be converted to 4321, "you" will be converted to "uoy". Here's the snippet.

Format data with custom number formats using VBA in Microsoft Excel | To change the number format of specific columns in excel use this VBA snippet. It coverts the number format of specified to specified format in one click.

Popular Articles:

50 Excel Shortcuts to Increase Your Productivity | Get faster at your task. These 50 shortcuts will make you work even faster on Excel.

The VLOOKUP Function in Excel | This is one of the most used and popular functions of excel that is used to lookup value from different ranges and sheets.

COUNTIF in Excel 2016 | Count values with conditions using this amazing function. You don't need filter your data to count specific value. Countif function is essential to prepare your dashboard.

How to Use SUMIF Function in Excel | This is another dashboard essential function. This helps you sum up values on specific conditions.

Leave a Reply

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

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.

Visit Us On TwitterVisit Us On FacebookVisit Us On Youtube