Whole numbers Functions in VBA

This page gives an overview of the VBA whole number (Byte,Integer,Long) functions with example code showing how they are used. A link is provided for each function to its documentation on microsoft learn VBA site.

Code VBA IntelliSense makes these function accessible under submenu VBA, see screenshot. intellisense menu with whole number functions.

Hovering a menu you see an explanation what a procedure does, and what the inserted code will look like, depending on changes you make in the Function Call Builder dialog.

Round - Round a number

The Round function returns a number rounded to a specified number of decimal places.

From the Code VBA toolbar, select VBA > String> Round » 


?Round(0.12335,4)
 0,1234
?Round(0.12345,4)
 0,1234
?Round(0.12355,4)
 0,1236
?Round(0.12365,4)
 0,1236

?WorksheetFunction.Round(0.12345,4)
 0,1235
?WorksheetFunction.RoundUp(0.12345,4)
 0,1235
?WorksheetFunction.RoundDown(0.12345,4)
 0,1234

?Round(0.00005,4)
 0
?WorksheetFunction.Round(0.00005,4)
 0,0001
?WorksheetFunction.RoundUp(0.00005,4)
 0,0001
?WorksheetFunction.RoundDown(0.00005,4)
 0
menu Round - Round a number

See https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/round-function

Int and Fix - Integer portion of a number

Returns the integer portion of a number.

Both Int and Fix remove the fractional part of number and return the resulting integer value. The difference between Int and Fix is that if number is negative, Int returns the first negative integer less than or equal to number, whereas Fix returns the first negative integer greater than or equal to number. For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.


i = Int(99.8)    ' Returns 99.'
i = Fix(99.2)    ' Returns 99.'

i = Int(-99.8)    ' Returns -100.'
i = Fix(-99.8)    ' Returns -99.'

i = Int(-99.2)    ' Returns -100.'
i = Fix(-99.2)    ' Returns -99.'

See https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/int-fix-functions