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 a 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 the 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 used the value from cell A1 (134.567) and then we used the CLNG function to convert that value into a long data type and it returned 135 in the result.
Notes
- CLNG will round that number that is greater than 0.5 and round down if lower than or equals 0.5.
- If you supply a number that 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.
- Back to the Excel VBA / VBA Functions