A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
re: another try
You can test if for me...
Sub ColorFormulaPrecedentsR1()
' Colors worksheet formula precedents on the active sheet.
' Nothing Left to Lose - Portland, Oregon - August 2021
On Error GoTo ErrFindingFormulas
Application.EnableCancelKey = xlErrorHandler
Dim FormulaRange As Excel.Range, FormulaArea As Excel.Range
Dim objGeneric As Excel.Range, objCell As Excel.Range, objCell2 As Excel.Range
Dim FormulaCell As Excel.Range, objWS As Excel.Worksheet, strTest As String
Dim N As Long, AreaCnt As Long, lngC As Long, blnFound As Boolean
Set objWS = ActiveSheet
Application.Cursor = xlWait
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
On Error Resume Next
Set FormulaRange = objWS.Cells.SpecialCells(xlCellTypeFormulas)
On Error GoTo ErrFindingFormulas
If Not FormulaRange Is Nothing Then
blnFound = True
AreaCnt = FormulaRange.Areas.Count 'Edited by moving this line here.
For Each FormulaArea In FormulaRange.Areas
DoEvents
N = N + 1
Application.StatusBar = "MAPPING SHEET... " & objWS.Name & _
VBA.Format(N / AreaCnt, " #00%")
For Each FormulaCell In FormulaArea.Cells
'Value returns an error, Formula does not.
If VBA.Len(FormulaCell.Formula) Then
On Error Resume Next
Set objGeneric = FormulaCell.Precedents
On Error GoTo ErrFindingFormulas
If Not objGeneric Is Nothing Then
If VBA.IsNull(objGeneric.MergeCells) Or objGeneric.MergeCells Then
VBA.MsgBox objGeneric.Address(False, False) & " is merged. ", \_
vbInformation, "Color Formula Precedents"
GoTo Exit\_FindFormulas
End If
strTest = FormulaCell.Formula
strTest = VBA.Mid(strTest, 2, 999)
If VBA.Left(strTest, 1) = VBA.Chr$(45) Then strTest = VBA.Mid(strTest, 2, 999)
On Error Resume Next
Set objCell2 = objWS.Range(strTest)
On Error GoTo ErrFindingFormulas
If Not objCell2 Is Nothing Then
FormulaCell.Font.Color = RGB(0, 128, 0)
End If
End If
End If
Set objGeneric = Nothing
Set objCell2 = Nothing
Next
Next
End If
Application.ScreenUpdating = True
Application.Cursor = xlDefault
If blnFound = False Then
VBA.MsgBox "No formulas were found. ", vbInformation, "Color Formula Precedents"
Else 'If lngC > 1 Then
VBA.MsgBox lngC & " Precedents were found. ", vbInformation, "Color Formula Precedents"
End If
Exit_FindFormulas:
On Error Resume Next
Set objWS = Nothing
Set objCell = Nothing
Set objCell2 = Nothing
Set objGeneric = Nothing
Set FormulaCell = Nothing
Set FormulaArea = Nothing
Set FormulaRange = Nothing
Application.StatusBar = False
Application.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.Cursor = xlDefault
Exit Sub
ErrFindingFormulas:
Beep
Application.ScreenUpdating = True
Application.Cursor = xlDefault
VBA.MsgBox "Error " & Err.Number & " - " _
& Err.Description & " ", vbCritical, "Color Formula Precedents "
Resume Exit_FindFormulas
End Sub
'---
NLtL