Thread: Rounding Ranges
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob H[_2_] Bob H[_2_] is offline
external usenet poster
 
Posts: 12
Default Rounding Ranges

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


"jdawg" wrote:

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