cells are:
3.141516
=10/6
=rand()
or blank
etc...
result:
=ROUND(3.141516,1)
=ROUND(10/6,1)
=ROUND(RAND(),1)
and if blank - leave blank (not ROUND(,1) )
and I would like to choose range, and decimal by InputBox or something
I found how to add ROUND() around formula, around Constants, with blank cells, with inputbox but all in a separate code, not together. I am not vba hero so I need help. thank you :)
Sub RoundNum()
Dim Rng As Range
Dim WorkRng As Range
Dim xNum As Integer
On Error Resume Next
xTitleId = "Round Numbers"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
xNum = Application.InputBox("Decimal", xTitleId, Type:=1)
For Each Rng In WorkRng
Rng.Value = Application.WorksheetFunction.Round(Rng.Value, xNum)
Next
End Sub
Sub Makro1()
Dim Str As String
For Each cell In Selection
Str = cell.FormulaR1C1
If Mid(Str, 1, 1) = "=" Then Str = Mid(Str, 2)
cell.FormulaR1C1 = "=ROUND(" & Str & ",1)"
Next cell
End Sub
on the end I did something like this:
Sub rRoundIt()
Dim rng As Range
Dim rngArea As Range
Dim AppCalc As Long
On Error Resume Next
With Application
AppCalc = .Calculation
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
Set rng = Union(Selection.SpecialCells(xlCellTypeFormulas, xlNumbers), _
Selection.SpecialCells(xlCellTypeConstants, xlNumbers))
For Each rngArea In rng
If Left(rngArea.Formula, 7) <> "=ROUND(" Then _
rngArea.Formula = "=ROUND(" & Replace(rngArea.Formula, Chr(61), vbNullString) & ", 1)"
Next rngArea
With Application
.ScreenUpdating = True
.Calculation = AppCalc
End With
End Sub
thank you Jeeped :)