1. CLng VBA function – Description
The CLng VBA function returns a value of the Long data type . It is an integer in the range –2,147,483,648 to 2,147,486,647 . The Long data type is 4 bytes in memory. The function can also be used to convert a number stored as text to a number in the Long data type. Attempting to call a function with an argument outside the range –2,147,483,648 to 2,147,486,647 will generate an error. We will also get an error if we enter a value that contains characters other than numbers as an argument.
2. VBA CLng Function – Syntax
CLng (Expression) As Long
Expression : Any integer between –2,147,483,648 and 2,147,486,647 stored in any data type (including String).
Function return : Long / An integer ranging from –2,147,483,648 to 2,147,486,647.
3. VBA CLng function – Example
How to use CLng function in VBA Excel? Below are examples of using the CLng function in the VisualBasic Editor.
Dim StrNumber As String StrNumber = "14522478" MsgBox CLng (StrNumber)
Dim intNumber As Integer intNumber = 32000 MsgBox CLng (intNumber)
4. VB CLng function – Additional information
- When used on numbers other than integers or outside the range of –2,147,483,648 to 2,147,486,647, an error will be returned.
5. CLng 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 .