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

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

The VBA CLNG 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 the long data type. In simple words, in VBA the long data type value can be anything between -2,147,483,648 and 2,147,483,647 (without any decimals).

Syntax

CLng(Expression)

Arguments

  • Expression: The value which you want to convert to the long data type.

Example

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

Sub example_CLNG()
Range("B1").Value = CLng(Range("A1"))
End Sub

In the above example, we have used the value from cell A1 (134.567) and then we have used the CLNG function to convert that value into long data type and it has returned 135 in the result.

Notes

  • CLNG will round that number which is greater than 0.5 and round down if lower than or equals 0.5.
  • If you supply a number which is out of the range of long data type (- 2.1 E+9 and 2.1 E+9), VBA will return the run-time 13 error.

Related Functions

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