How to use the VBA INT Function (Syntax + Example)

HomeVBA Functions LIST (Category Wise)How to use the VBA INT Function (Syntax + Example)

The VBA INT function is listed under the math category of VBA functions. When you use it in a VBA code, it con round down a number to an integer. In simple words, it rounds a positive number towards zero and a negative number away from zero. It simply works like the INT function in the worksheet.

Syntax

Int(Number)

Arguments

  • Number: The numeric value from which you want the integer part of.

Example

To practically understand how to use VBA INT function, you need to go through the below example where we have written a vba code by using it:

Sub example_INT()
Range("B1").Value = Int(Range("A1"))
End Sub

In the above code, we have used INT to get the integer part from the value (13.54) that we have in the cell A1 and return the result in the cell B1. And when we run the code it has returned the 13 in the cell B1.

Notes

  • If the value specified is a value other than a number or a string that can’t be recognized as a number, VBA will return the run-time 13 error.
  • If the supplied number is positive then it rounds that number towards zero and if the supplied number is negative then away from zero.

Related Functions

ABS | ATN | COS | EXP | FIX | LOG | RND | ROUND | SGN | SIN | SQR | TAN