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 » 




See also 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