Rounding Ranges

J

jdawg

I am just curious if anyone knows how to either do a global round or do
a round of each of the cells in a range. I currently have the
following code in place but it only rounds the active cell.

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

Sub ConfirmRound()
YesNo = MsgBox("Clicking Yes will...", vbYesNo + vbCritical,
"WARNING!!!")
Select Case YesNo
Case vbYes
Call Round
Case vbNo
End Select
End Sub


I am also curious what is the code so when a user opens excel, they are
taken to a certain location no matter what location was saved prior.

Thanks
 
B

Bob H

The following code has worked well for me. It adds the ROUND formula to any
cell. FIrst select the range you want to round and then run the macro.

Sub Roundit()
On Error GoTo ErrorHandler
Roundto = InputBox("Round to How many Places?", "Round!", 0)
Roundto = CLng(Roundto)

For Each Cell In Selection
Rawnum = Cell.Formula
If Left(Rawnum, 6) = "=ROUND" Then
Cell.Formula = Left(Rawnum, Len(Rawnum) - 2) & Roundto & ")"
Else: Rawnum = IIf(Left(Rawnum, 1) = "=", Right(Rawnum, Len(Rawnum) - 1),
Rawnum)
Cell.Formula = "=round(" & Rawnum & "," & Roundto & ")"
End If
Next Cell
ErrorHandler:
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top