MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Rounding Function using current cell value as number

Posted by Bryan on June 29, 2000 1:27 PM

I need to use the round function in a macro to round say 254.2365 to 254. The macro works but retains the value 254.2365 if I use the macro in other cells. How can I refer the macro to any cell using whatever number is in the cell?

Posted by Ryan on June 29, 0100 2:17 PM

Give a little more info on what's happening and I'll take a look at it.


Posted by Bryan on June 29, 0100 2:51 PM

This is what the macro says:
Sub Macro1()
' Macro1 Macro
' Macro recorded 30/06/2000 by Bryan Barrett
ActiveCell.FormulaR1C1 = "154.25"
ActiveCell.FormulaR1C1 = "=ROUND(154.25,0)"
End Sub
I try and run this macro against another cell with a differnent number and the macro returns:
'=ROUND(154.25,0) again,
but the value in the cell was 164.25.
How can this macro be used against any cell? Many Thanks, Bryan

Posted by Ryan on June 29, 0100 3:00 PM

Here you go:

Sub RoundMe()

ActiveCell.Formula = Application.WorksheetFunction.Round(ActiveCell.Value, 0)
End Sub
Let me know how it works. Good Luck!

Posted by Bryan on June 29, 0100 3:22 PM

Brilliant! Many thanks,