Excel Functions Tutorials

- VBA
- VBA Tutorial
- VBA Functions in Excel
- VBA ArrayList
- VBA Arrays Function in Excel
- VBA Activate Sheet
- VBA Break
- VBA Borders
- VBA Boolean
- VBA ByRef
- VBA Code
- VBA Const
- VBA Class Modules
- VBA Count
- VBA COUNTA
- VBA COUNTIF
- VBA Comment Block
- VBA Match Function
- VBA LEFT Function
- VBA Right Function
- VBA Like
- VBA LEN
- VBA Long
- VBA Today
- VBA Now
- VBA Time Function
- VBA Timer
- VBA TimeValue
- VBA Weekday
- VBA ROUND
- VBA RoundUp
- VBA Random Numbers
- VBA ReDIM Function
- VBA Rename Sheet
- VBA Protect Sheet
- VBA Remove Duplicates
- VBA Concatenate
- Copy Paste in VBA
- VBA Paste
- VBA Print
- VBA Date Function
- VBA DateDiff Function
- VBA DateAdd Function
- VBA DatePart
- VBA Data Type
- VBA Dictionary
- VBA Debug Print
- VBA Charts
- VBA CDBL
- VBA CSTR
- VBA Chr
- VBA ChDir
- VBA ENUM
- VBA RegEx
- VBA Mid Function
- VBA Max
- VBA Find Function
- VBA Find and Replace
- VBA Trim Function
- VBA Text
- VBA OFFSET Function
- VBA MOD Function
- VBA Split Function
- VBA UBound Function
- VBA Union
- VBA Transpose
- VBA INT
- VBA InStr
- VBA INSTRREV
- VBA Intersect
- VBA Integer
- VBA DIR Function
- VBA OR Function
- VBA AND
- VBA Operators
- VBA Not Equal
- VBA Worksheet Function
- VBA Workbook
- VBA ThisWorkbook
- VBA Worksheets
- VBA Write Text File
- VBA Hyperlinks
- VBA String Functions
- VBA StrComp
- VBA StrConv
- VBA Sub
- VBA Call Sub
- VBA End
- VBA Wait
- VBA Option Explicit
- VBA SubString
- VBA Subscript Out of Range
- VBA IIF
- VBA IF OR
- VBA IFERROR
- VBA On Error
- VBA OverFlow Error
- VBA 1004 Error
- VBA Error Handling
- VBA Type
- VBA Type Mismatch Error
- VBA IsEmpty
- VBA ISNULL
- VBA Input Box
- VBA MsgBox
- VBA Text Box
- VBA Format
- VBA Format Number
- VBA Conditional Formatting
- VBA AutoFill
- VBA AutoFilter
- VBA Color Index
- VBA Font Color
- VBA Clear Contents
- VBA Collection
- VBA Paste Special
- VBA Progress Bar
- VBA GoTo
- VBA Userform
- VBA Close UserForm
- User Defined Function in Excel VBA
- VBA Outlook
- VBA JOIN
- VBA LCase
- VBA UCase
- VBA Select Case
- VBA Select Cell
- VBA Selection
- VBA Active Cell
- VBA Set
- VBA Sleep
- VBA Pause
- VBA Range Objects
- VBA Range Cells
- VBA UsedRange
- VBA Loop
- VBA Break For Loop
- VBA For Each Loop
- VBA For Next Loop
- VBA Do Until Loop
- VBA File Copy
- VBA FileDialog
- VBA FileSystemObject (FSO)
- VBA Cells
- VBA Last Row
- VBA Insert Row
- VBA Hide Columns
- VBA New Line
- VBA GetOpenFilename
- VBA GetObject
- VBA Delete File
- VBA Delete Row
- VBA Insert Columns
- VBA Delete Column
- VBA Val
- VBA Value
- VBA Variant
- VBA Variable Declaration
- VBA Global Variables
- VBA Pivot Table
- VBA Refresh Pivot Table
- VBA PowerPoint
- VBA Send Email from Excel

- Financial Functions in Excel (17+)
- Logical Functions in Excel (15+)
- TEXT Functions in Excel (29+)
- Lookup Reference in Excel (44+)
- Maths Functions in Excel (52+)
- Date and Time Function in Excel (22+)
- Statistical Function in Excel (50+)
- Information Functions in Excel (5+)
- Excel Charts (48+)
- Excel Tools (98+)
- Excel Tips (178+)

Related Courses

## Excel VBA Integer

Data types are so important in any coding language because all the variable declaration should be followed by data type assigning to those variables. We have several data types to work with and each data type has its own advantages and disadvantages associated with it. When we are declaring variables is important to know details about the particular data type. This is the article dedicated for “Integer” data type in VBA. We will show you the complete picture of “Integer” data type.

### What is the Integer Data Type?

Integers are whole numbers which could be positive, negative, and zero but not a fractional number. In VBA context “Integer” is a data type we assign to the variables. It is a numerical data type which can hold of whole numbers without decimal positions. Integer data type 2 bytes of storage which is half of the VBA LONG datatype i.e. 4 bytes.

### Examples of Excel VBA Integer Data Type

Below are the examples of VBA Integer Data type.

#### Example #1

When we declare a variable it is necessary to assign a data type to it and integer one of them which is commonly used by all the users based on the requirements.

As I told integer can only hold of whole numbers, not any fractional numbers. Follow the below steps to see the example of a VBA integer data type.

**Step 1: **Declare the variable as Integer.

**Code:**

Sub Integer_Example() Dim k As Integer End Sub

**Step 2: **Assign the value of 500 to the variable “k”.

**Code:**

Sub Integer_Example1() Dim k As Integer k = 500 End Sub

**Step 3: **Show the value in the VBA message box.

**Code:**

Sub Integer_Example1() Dim k As Integer k = 500 MsgBox k End Sub

When we run the code using F5 key or manually then, we can see 500 in the message box.

#### Example #2

Now I will assign the value as -500 to the variable “k”.

4.6 (247 ratings)

**Code:**

Sub Integer_Example2() Dim k As Integer k = -500 MsgBox k End Sub

Run this code manually or press F5 then, it will also show the value of -500 in the message box.

#### Example #3

As I told VBA Integer data type can hold only whole numbers not fraction numbers like 25.655 or 47.145.

However, I will try to assign the fraction number to a VBA Integer data type. For an example look at the below code.

**Code:**

Sub Integer_Example3() Dim k As Integer k = 85.456 MsgBox k End Sub

I have assigned 85.456 to the variable “k”. I will run this VBA code to see what the result is.

- It has returned the result as 85 even though I have assigned the value of the fraction number. This is because of VBA round the fraction numbers to the nearest integer.
- All the fraction number which are less than 0.5 will be rounded down to the nearest integer. For an example 2.456 = 2, 45.475 = 45.
- All the fraction number which are greater than 0.5 will be rounded up to the nearest integer. For an example 10.56 = 11, 14.789 = 15.

To have another look at the roundup integer lets the value of “k” to 85.58.

**Code:**

Sub Integer_Example3() Dim k As Integer k = 85.58 MsgBox k End Sub

When I run this code using F5 key or manually it will return 86 because anything more than 0.5 will be rounded up to the next integer number.

### Limitations of Integer Data Type in Excel VBA

**Overflow Error: **Integer data type should work fine as long as the assigned value is between -32768 to 32767. The moment it crosses the limit on either side it will cause you an error.

For an example look at the below code.

**Code:**

Sub Integer_Example4() Dim k As Integer k = 40000 MsgBox k End Sub

I have assigned the value of 40000 to the variable “k”.

Since I have complete knowledge on Integer Data Type for sure I know it doesn’t work because integer data type cannot hold the value anything more than 32767.

Let’s run the code manually or through F5 key and see what happens.

Oops !!!

I got the error as “Overflow” because Integer data type cannot hold anything more than 32767 for positive numbers and -32768 for negative numbers.

**Type Mismatch Error: **Integer data can only hold numerical values between -32768 to 32767. If any number assigned more than these numbers will show Overflow error.

Now I will try to assign text or string values to it. In the below example code I have assigned the value as “Hello”.

**Code:**

Sub Integer_Example4() Dim k As Integer k = "Hello" MsgBox k End Sub

I will run this code through run option or manually and see what happens.

It is showing the error as “Type mismatch” because we cannot assign a text value to the variable “integer data type”.

### Recommended Articles

This has been a guide to VBA Integer Data type in excel. Here we discussed how to use VBA Integer data type in Excel and its limitations along with the examples and downloadable excel template.

- RoundUp in VBA
- How to Close UserForm in Excel VBA?
- ByRef Function Argument in VBA
- VBA Overflow Error
- 2 Types of Data Types in VBA
- How to handle errors in VBA?
- VBA Function IsEmpty
- Make a UserForm in VBA
- How to use Paste Special in VBA?

- 3 Courses
- 12 Hands-on Projects
- 43+ Hours
- Full Lifetime Access
- Certificate of Completion