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).
- Expression: The value which you want to convert to an integer.
To practically understand how to use VBA CINT function, you need to go through the below example where we have written a vba code by using it:
Sub example_CINT() Range("B1").Value = CInt(Range("A1")) End Sub
In the above example, we have used the value from cell A1 (9.76) and then we have used the CINT function to convert that value into an integer data type and it has returned 10 in the result.
- CINT will round that number which is greater than 0.5 and round down if lower than or equals 0.5.
- If you supply a number which is out of the range of integer data type (-32,768 and 32,767), VBA will return the run-time 13 error.