The VBA FIX Function

VBA Fix and Int Functions

The VBA Fix function is very similar to the VBA Int function, which also returns the integer portion of a number.

The difference between these two functions is:

  • The Fix function rounds both positive and negative numbers towards zero;
  • The Int function rounds positive numbers towards zero and negative numbers away from zero.
Related Functions:
VBA Int
VBA Round

Description

The VBA Fix function truncates a supplied number to an integer.

The syntax of the function is:

Fix( Number )

Where the Number argument is the number that you want the integer part of.


VBA Fix Function Examples

' Return the integer parts of the numbers 77.7 and -77.7
Dim int1 As Integer
Dim int2 As Integer
int1 = Fix( 77.7 )
int2 = Fix( -77.7 )
' Now, int1 = 77 and int2 = -77

In the above VBA code:

Note that the VBA Fix function rounds both positive and negative values towards zero.


VBA Fix Function Error

If the Fix function is supplied with a value that cannot be interpreted as a number, it will return the error:

Run-time error '13': Type mismatch

VBA Run Time Error 13 Message Box