CInt VBA function – How to convert data to Integer type

Last Updated on January 11, 2023 by token

1. CInt VBA function – Description

The CInt VBA function returns a value of the Integer data type . It is an integer in the range -32768 to 32767 . The Integer data type takes 2 bytes in memory and is therefore very efficient. This way, we can convert low-valued numbers to store them in more
efficient data types. The function can also be used to convert a number written as text to a number in the Integer data type. Attempting to call a
function with an argument outside the range -32768 to 32767 will generate an error.

2. VBA CInt function – Syntax

CInt (Expression) As Integer

Expression : Any integer in the range -32768 to 32767 stored in any data type (including String).

Function return : Integer / An integer in the range -32768 to 32767.

3. VBA CInt function – Example

How to use the CInt function in VBA Excel? Below are examples of using the CInt function in the VisualBasic Editor.

Example 1:

Dim StrNumber As String
StrNumber = "255"
MsgBox CInt (StrNumber)

Example 2:

Dim LngNumber As Long
LngNumber = 123
MsgBox CInt (LngNumber)
Excel VBA functions - CINT VBA function
Excel VBA functions – CINT VBA function

4. VB CInt function – Additional information

  • A function used for numbers other than integers or outside the range -32768 to 32767 will return an error.

5. CInt 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: