VBA CLng Function – How to Convert Data to Long Type

Last Updated on January 11, 2023 by token

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.

Example 1:

Dim StrNumber As String
StrNumber = "14522478"
MsgBox CLng (StrNumber)

Example 2:

Dim intNumber As Integer
intNumber = 32000
MsgBox CLng (intNumber)
Excel VBA Functions - CLng VBA function
Excel VBA Functions – CLng VBA function

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, Excel 2019, Excel 2021, Excel 365.

The article is part of the VBA Excel function list. You can find a list of all VBA functions at this address:  VBA functions .

Leave a comment

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

%d bloggers like this: