Today I'm going to explain you another very useful VBA function. It is Fix function. You can use this function to get the integer part of a numerical value. For an example, if you parse value 102.5 to the Fix function it will return 102
Here below is a sample subroutine from which you can get a clear idea about how this function works.
Sub FixFunctionExample() Dim SampleValues(4) As Double SampleValues(0) = 0.25 SampleValues(1) = 5.78 SampleValues(2) = 100.5 SampleValues(3) = -25.8 SampleValues(4) = -30.2 For i = LBound(SampleValues) To UBound(SampleValues) Debug.Print Fix(SampleValues(i)) Next i End Sub |
If you run the above code, you will get following result in the intermediate window.
0
5
100
-25
-30