Sunday, May 20, 2007

Rounding Numbers

Here I will show how to perform different types of rounding. Key in 12345 in any active cell and run the following code.

Sub Round()
ActiveCell = Application.round(ActiveCell, -3)
End Sub

This code round to the nearest 1000 thus giving the value 12000.

ActiveCell = Application.Ceiling(ActiveCell, 1000)
Replace with this line of code and it will round up to the next 1000 ie 13000
ActiveCell = Application.Floor(ActiveCell, 1000)
Replace with this line of code and it will round down to the next 1000 ie 12000

No comments:

Post a Comment