View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bill Renaud Bill Renaud is offline
external usenet poster
 
Posts: 417
Default problems recording macro_value or formula?

It appears that you are simply iterating through all of the cells in an
entire range of the worksheet. If so, then you can use a For Each rngCell
.... type of program statement. (I defined rngAllData to be all of the cells
on the active worksheet, but you can comment this line out and put in the
line below it, if you need to.)

Change SomeValue to be the value that you want to compare each cell value
to.
This routine skips over cells that are not a formula, or ones that have a
formula that evaluates to an error for some reason.

This routine encloses the entire formula in parentheses, then adds a "/2"
at the end of the formula.


Public Sub ReplaceFormulas()
Const SomeValue As Double = 1000.123
Dim wsActive As Worksheet
Dim rngAllData As Range
Dim rngCell As Range

Set wsActive = ActiveSheet
Set rngAllData = wsActive.UsedRange 'Use all cells on the worksheet.
'or if you really must use only a fixed range of cells:
'Set rngAllData = wsActive.Range("A11:DC1084")

For Each rngCell In rngAllData
With rngCell
If .HasFormula _
Then
If Not IsError(.Value) _
Then
If .Value < SomeValue _
Then
.Formula = "=(" _
& Right$(.Formula, Len(.Formula) - 1) _
& ")/2"
End If
End If
End If
End With
Next rngCell
End Sub

--
Regards,
Bill Renaud