Excel VBA CInt Function

VBA CInt Function: The VBA Cint function converts the specified expression into an Integer.

Syntax

Cint (Expression)

Parameter

Expression (required) – This parameter represents the expression that you want to convert to an Integer wherein the supplied expression must be between -32,768 and 32,767.

Return

This function returns an integer value ranging between -32,768 and 32,767 after converting the given expression to the integer data type.

Example 1

Sub CIntFunction_Example1()
 ' Converting the supplied value into Integer
 Dim int_val As Integer
 int_val = CInt(69.9)
 ' The variable int_val will return 70.
 Cells(1, 1).Value = int_val
 End Sub 

Output

70

VBA CInt Function

Example 2

Sub CIntFunction_Example2()
 ' Converting the supplied value into Integer
 Dim int_val As Integer
 int_val = CInt("345")
 ' The variable int_val will return 355 (345+10).
 Cells(1, 1).Value = int_val + 10
 End Sub 

Output

355

VBA CInt Function

Example 3

Sub CIntFunction_Example3()
 ' Converting the supplied Value into Integer
 Dim int_val As Integer
 'passing value less than -32,768
 int_val = CInt(-32800)
 ' The variable int_val will return a run-time overflow error.
 Cells(1, 1).Value = int_val
 End Sub 

Output

VBA CInt Function