Excel VBA INT Function

VBA INT Function: The INT function in VBA rounds the given supplied number down and returns an integer value. The positive numbers are rounded to zero, and the negative numbers are rounded away from zero.

Syntax

Int (Number)

Parameter

Number (required) –This parameter represents the number that you want the integer value of.

Return

This function returns the rounded off integer value for the supplied number.

Example 1

Sub IntFunction_Example1()
 ' Rounding a positve number towards 0
 Dim int_val As Integer
 Dim int2 As Integer
 int_val = Int(12.78)
 ' The variable int_val will return 12
 Cells(1, 1).Value = int_val
 End Sub 

Output

12

VBA INT Function

Example 2

Sub IntFunction_Example1()
 ' Rounding a negative number away from 0
 Dim int_val As Integer
 Dim int2 As Integer
 int_val = Int(-12.78)
 ' The variable int_val will return -13
 Cells(1, 1).Value = int_val
 End Sub 

Output

-13

VBA INT Function

Example 3

Sub IntFunction_Example3()
 Dim int_val As Integer
 Dim int2 As Integer
 'for other formats apart from number
 int_val = Int("Hey")
 ' The variable int_val will return run time error
 Cells(1, 1).Value = int_val
 End Sub 

Output

VBA INT Function