Sub test()
Dim result As Long
Const i = 5.65
result = Int(i) - 1 * (Int(i) > i)
MsgBox result
End Sub
I thought it was slower, but didn't testWhy not use Application.WorksheetFunction.Floor?
Sub test()
Dim result As Long
Dim starttime As Double
Dim i As Long
starttime = Timer
For i = 1 To 3000000
'result = Int(5.65) - 1 * (Int(5.65) > i)
result = Application.WorksheetFunction.Floor(5.65, 1)
Next i
MsgBox Timer - starttime
End Sub
Sub test()
Dim result As Long
Dim starttime As Double
Dim i As Long
starttime = Timer
For i = 1 To 3000000
'result = Int(5.65) - 1 * (Int(5.65) > i)
result = Application.WorksheetFunction.Floor(5.65, 1)
Next i
Debug.Print Timer - starttime
starttime = Timer
For i = 1 To 3000000
result = Int(5.65) - 1 * (Int(5.65) > i)
'result = Application.WorksheetFunction.Floor(5.65, 1)
Next i
Debug.Print Timer - starttime
End Sub
I found Round() but I can't find a Floor() math function within the VBA code side of the excel.
For those not math inclined, Floor(5.65) = 5, whereas Round(5.65) = 6.