J
Jim
Below is a piece of code that I've been trying to modify. The code is
supposed to walk through the entire workbook and identify each cell
that has dependents. As I am working with a huge model, this would
take far too much time, and I would like to limit the macro to run
only a select few sheets. It would actually be even better if it only
ran on the active sheet, but I don't want to be picky. Any ideas?
=============================
Sub HighlightInputCells()
Dim wks As Worksheet
Dim rngFormulas As Range
Dim rngCell As Range
Dim vSheetLst As Variant
vSheetList = Array("Sheet2", "Sheet1")
Application.ScreenUpdating = False
For i = LBound(vSheetList) To UBound(vSheetList)
Worksheets(sheetlist(i)).Activate
On Error Resume Next
Set rngFormulas =
Union(wks.UsedRange.SpecialCells(xlCellTypeBlanks),
wks.UsedRange.SpecialCells(xlCellTypeConstants))
If Not rngFormulas Is Nothing Then
For Each rngCell In rngFormulas
If HasDependents(rngCell) Then rngCell.Interior.ColorIndex
= 3
Next rngCell
Set rngFormulas = Nothing
End If
Next wks
Application.ScreenUpdating = True
End Sub
Function HasDependents(rngCheck As Range) As Boolean
Dim lngSheetCounter As Long
Dim lngRefCounter As Long
Dim rngDep As Range
On Error Resume Next
With rngCheck
.ShowDependents False
Set rngDep = .NavigateArrow(False, 1, 1)
If rngDep.Address(external:=True) =
rngCheck.Address(external:=True) Then
HasDependents = False
Else
HasDependents = (Err.Number = 0)
End If
.ShowDependents True
End With
End Function
supposed to walk through the entire workbook and identify each cell
that has dependents. As I am working with a huge model, this would
take far too much time, and I would like to limit the macro to run
only a select few sheets. It would actually be even better if it only
ran on the active sheet, but I don't want to be picky. Any ideas?
=============================
Sub HighlightInputCells()
Dim wks As Worksheet
Dim rngFormulas As Range
Dim rngCell As Range
Dim vSheetLst As Variant
vSheetList = Array("Sheet2", "Sheet1")
Application.ScreenUpdating = False
For i = LBound(vSheetList) To UBound(vSheetList)
Worksheets(sheetlist(i)).Activate
On Error Resume Next
Set rngFormulas =
Union(wks.UsedRange.SpecialCells(xlCellTypeBlanks),
wks.UsedRange.SpecialCells(xlCellTypeConstants))
If Not rngFormulas Is Nothing Then
For Each rngCell In rngFormulas
If HasDependents(rngCell) Then rngCell.Interior.ColorIndex
= 3
Next rngCell
Set rngFormulas = Nothing
End If
Next wks
Application.ScreenUpdating = True
End Sub
Function HasDependents(rngCheck As Range) As Boolean
Dim lngSheetCounter As Long
Dim lngRefCounter As Long
Dim rngDep As Range
On Error Resume Next
With rngCheck
.ShowDependents False
Set rngDep = .NavigateArrow(False, 1, 1)
If rngDep.Address(external:=True) =
rngCheck.Address(external:=True) Then
HasDependents = False
Else
HasDependents = (Err.Number = 0)
End If
.ShowDependents True
End With
End Function