VBA CINT Function (Syntax + Example)

- Written by Puneet

The VBA CINT function is listed under the data type conversion category of VBA functions. When you use it in a VBA code, it converts an expression into an integer. In simple words, an integer as per VBA’s integer data type can be any value between -32,768 and 32,767 (without any decimals).

Syntax

CInt(Expression)

Arguments

  • Expression: The value which you want to convert to an integer.

Example

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

example-vba-cint-function
Sub example_CINT()
Range("B1").Value = CInt(Range("A1"))
End Sub

In the above example, we used the value from cell A1 (9.76) and then we used the CINT function to convert that value into an integer data type and it returned 10 in the result.

Notes

  • CINT will round that number that is greater than 0.5 and round down if it is lower than or equals 0.5.
  • If you supply a number that is out of the range of integer data type (-32,768 and 32,767), VBA will return the run-time 13 error.