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 VBA Fix function truncates a supplied number to an integer.
The syntax of the function is:
Where the Number argument is the number that you want the integer part of.
' Return the integer parts of the numbers 77.7 and -77.7
Dim int1 As Integer
Dim int2 As Integer
int1 = Fix( 77.7 )
' Now, int1 = 77 and int2 = -77
int2 = Fix( -77.7 ) |
In the above VBA code:
Note that the VBA Fix function rounds both positive and negative values towards zero.
If the Fix function is supplied with a value that cannot be interpreted as a number, it will return the error: