excel vba round code example
Example 1: vba round number
Function RoundTo(pNumber As Long, pFactor As Long)
RoundTo = Round(pNumber / pFactor) * pFactor
End Function
Sub TestMe()
Debug.Print RoundTo(2543, 10)
Debug.Print RoundTo(2546, 10)
Debug.Print Application.RoundUp(10.1, 0)
Debug.Print Application.RoundUp(10.6, 0)
Debug.Print Application.RoundDown(10.6, 0)
End Sub
Example 2: how to correct a number to 2 decimal places in vba
Sub rounding()
ActiveCell.Select Selection.Value = Format(ActiveCell, "#.00")
End Sub