Excel VBA Fix Function
VBA Fix Function: The Fix function in VBA truncates the given number to an integer and returns the rounded off integer number. This function both positive and negative numbers to zero.
Syntax
Fix (Number)
Parameter
Number (required) – This parameter represents the number that you want the integer part of.
Return
This function returns an integer value after truncating the specified number.
Example 1
Sub FixFunction_Example1() ' Returning the integer value of the given number Dim fix_val As Integer 'passing negative number fix_val = Fix(-17.89) ' The variable fix_val will return value -17 Cells(1, 1).Value = fix_val End Sub
Output
-17
Example 2
Sub FixFunction_Example2() ' Returning the integer value of the given number Dim fix_val As Integer 'it returns both positive negative numbers towards zero fix_val = Fix(17.89) ' The variable fix_val will return value 17 Cells(1, 1).Value = fix_val End Sub
Output
17
Example 3
Sub FixFunction_Example3() ' Returning the integer value of the given number Dim fix_val As Integer 'passing string value fix_val = Fix("Hey") ' The variable fix_val will return run-time error Cells(1, 1).Value = fix_val End Sub
Output