VBA CLNG Function

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

What is VBA CLNG Function

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).

how to use it

To use VBA's CLNG function you need to understand its syntax and arguments:




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

Example to use CLNG Function in VBA

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.


Below are some important points which you need to take care while using CLNG function in VBA.

  • 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.

About the Author

puneet one point one

Puneet is using Excel since his college days. He helped thousands of people to understand the power of the spreadsheets and learn Microsoft Excel. You can find him online, tweeting about Excel, on a running track, or sometimes hiking up a mountain.