View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
JLatham JLatham is offline
external usenet poster
 
Posts: 3,365
Default Help with Code from John Mansfield

Try this variation:

Sub NewRounding()
Dim cellRange As Range
Dim Rng As Range
Dim cellFormula As String

Set cellRange = Range("A1:C10")
For Each Rng In cellRange
If Not IsEmpty(Rng) Then
If IsNumeric(Rng) Then
If Rng.HasFormula Then
cellFormula = Mid(Rng.Formula, _
2, 1024)
If InStr(UCase(cellFormula), _
UCase("Round")) = 0 Then
Rng.Formula = "=Round(" _
& cellFormula & ",0)"
End If
Else
Rng.Formula = _
"=Round(" & Rng.Value & ",0)"
End If
End If
End If
Next
End Sub


"jon" wrote:

Hi,
In an earlier post John provided me with a macro to round the values in a
selected cell range.
The code was:
Sub Add_Rounding()

Dim cellRange As Range
Dim Rng As Range
Dim cellFormula As String

On Error Resume Next

Set cellRange = Range("A1:C10").SpecialCells(xlCellTypeFormulas)

For Each Rng In cellRange

cellFormula = Mid(Rng.Formula, 2, 1024)
If InStr(UCase(cellFormula), UCase("Round")) = 0 Then
Rng.Formula = "=round(" & cellFormula & ",0)"
End If

Next Rng

End Sub

Unfortunately, some of my worksheets have fixed values not calculated values
in the fields, and the macro doesn't amend any cell that doesn't begin with
an = sign.

Can anyone tell me how to make it work for fixed values.

Thanks

Jon