View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default How to zero out cells with formulas in them but no precedents?

Sub Zeroing()


Dim rng As Range

' Set rng = ActiveSheet.UsedRange _
.SpecialCells(xlCellTypeConstants, xlNumbers)
' For Each cell In rng
' If Not IsDate(cell.Value) Then
' cell.Value = 0
' cell.Font.ColorIndex = 5
' End If
' Next cell
Set rng = ActiveSheet.UsedRange _
.SpecialCells(xlCellTypeFormulas, xlNumbers)
For Each cell In rng
If cell.Precedents is nothing Then
cell.Value = 0
cell.Font.ColorIndex = 5
End If
Next cell

'
End Sub

Assumes precedents would be on the same sheet.

--
Regards,
Tom Ogilvy


"Mike Piazza" wrote in message
...
I have the below code I am using to try to zero out constant numbers in
models. The section I have 'ed out seems to work fine. The second

section I
am trying to use to find cells which have formulas in them but no predents
and zero those.
Thanks for the help.

Sub Zeroing()


Dim rng As Range

' Set rng = ActiveSheet.UsedRange.SpecialCells(xlCellTypeConst ants,
xlNumbers)
' For Each cell In rng
' If Not IsDate(cell.Value) Then
' cell.Value = 0
' cell.Font.ColorIndex = 5
' End If
' Next cell
Set rng = ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormu las,
xlNumbers)
For Each cell In rng
If Not shprec(ActiveCell) Then
cell.Value = 0
cell.Font.ColorIndex = 5
End If
Next cell

'
End Sub

Function shprec(cell As Range)

On Error GoTo noprec
cell.Precedents.Show
shprec = True
Exit Function

noprec:
shprec = False

End Function