VBA Int Function

VBA Int Function in Excel

VBA Int function in Excel is categorized as Math(Mathematical) & Trig function. This is a built-in Excel VBA Function. This function rounds a specified number down to its nearest integer. This function returns an integer portion and always returns a double value for valid argument.

We can use this function in Excel and VBA. This function we use in either procedure or function any number of times in a Excel VBA editor window. Let us learn what is the syntax and parameters of the Int function, where we can use this Int Function and real-time examples in Excel VBA.

Syntax of VBA Int Function

The syntax of the Int Function in VBA is

Int(Number)

The Int function returns a double value.

Parameters or Arguments:

The Int function has one argument in Excel VBA.
where
Number:The Number is a required parameter. This argument represents a number or numeric value. We use this parameter to round down the number to nearest integer. The number is Null, then it returns Null. And the specified number is zero(0), it returns zero(0).

Where we can apply or use VBA Int Function?

We can use this Int Function in VBA MS Office 365, MS Excel 2016, MS Excel 2013, 2011, Excel 2010, Excel 2007, Excel 2003, Excel 2016 for Mac, Excel 2011 for Mac, Excel Online, Excel for iPhone, Excel for iPad, Excel for Android tablets and Excel for Android Mobiles.

Example 1: Round down the number(1234.5) to nearest integer

Here is a simple example of the VBA Abs function. This below example round down the number(1234.5) to nearest integer.

'Round down the number(1234.5)
Sub VBA_Int_Function_Ex1()

    'Variable declaration
    Dim iValue As Integer
    Dim dResult As Double
    
    iValue = 1234.5
        
    dResult = Int(iValue)
        
    MsgBox "Round down the number(1234.5) is : " & dResult, vbInformation, "VBA Int Function"
    
End Sub

Output: Here is the screen shot of the first example output.
VBA Int Function

Example 2: Round down the number(-1234.5) to nearest integer

Here is a simple example of the VBA Abs function. This below example round down the number(-1234.5) to nearest integer.

'Round down the number(-1234.5)
Sub VBA_Int_Function_Ex2()

    'Variable declaration
    Dim iValue As Integer
    Dim dResult As Double
    
    iValue = -1234.5
        
    dResult = Int(iValue)
        
    MsgBox "Round down the number(-1234.5) is : " & dResult, vbInformation, "VBA Int Function"
    
End Sub

Output: Here is the screen shot of the second example output.
VBA Int Function

Example 3: Round down the number(‘1234.5’) to nearest integer

Here is a simple example of the VBA Abs function. This below example round down the number(‘1234.5’) to nearest integer.

'Round down the number('1234.5') 
Sub VBA_Int_Function_Ex3()

    'Variable declaration
    Dim iValue As String
    Dim dResult As Double
    
    iValue = "1234.5"
        
    dResult = Int(iValue)
        
    MsgBox "Round down the number('1234.5') is : " & dResult, vbInformation, "VBA Int Function"
    
End Sub

Output: Here is the screen shot of the third example output.
VBA Int Function

Example 4: Round down the number(0.5) to nearest integer

Here is a simple example of the VBA Abs function. This below example Round down the number(0.5) to nearest integer.

'Round down the number(0.5) 
Sub VBA_Int_Function_Ex4()

    'Variable declaration
    Dim iValue As Integer
    Dim dResult As Double
    
    iValue = 0.5
        
    dResult = Int(iValue)
        
    MsgBox "Round down the number(0.5) is : " & dResult, vbInformation, "VBA Int Function"
    
End Sub

Output: Here is the screen shot of the third example output.
VBA Int Function

Instructions to Run VBA Macro Code or Procedure:

You can refer the following link for the step by step instructions.

Instructions to run VBA Macro Code

Other Useful Resources:

Click on the following links of the useful resources. These helps to learn and gain more knowledge.

VBA Tutorial VBA Functions List VBA Arrays in Excel Blog

VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers

Leave a Reply