Color or Format a Formula Referenced Cells - Precedents

< Back to Search results

 Category: [Excel]  Demo Available 


Color or Format a Formula Referenced Cells - Precedents


Got any Excel Questions? Free Excel Help 


Color Formulae Reference Cells

Here is some VBA code that will color the precedent cells of any single cell formula.

Sub ColorCellReferences()

    Dim rFormulaCell As Range


    Set rFormulaCell = Sheet1.Range("A1")

    On Error GoTo PrecedentError

    With rFormulaCell

        .ShowPrecedents (False)

        .NavigateArrow True, 1, 1

        With Selection

            If .Address = rFormulaCell.Address _

            Then GoTo PrecedentError

            .Interior.ColorIndex = 6

        End With

        Application.Goto .Cells(1, 1)

        .ShowPrecedents (True)

    End With

    Exit Sub


     MsgBox "No  formula, or no formula with Precedents in cell"


End Sub


Microsoft ® and Microsoft Excel ® are registered trademarks of Microsoft Corporation. OzGrid is in no way associated with Microsoft


See also:

Change Text to Upper Case or Proper Case
Automatically Add Date, Time or Date & Time
Display Excel AutoFilter Criteria
Use AutoFilter in Excel VBA to Filter by Date & Time
Formatting Cells Shortcut keys


Free Training Course: Lesson 1 - Excel Fundamentals


See also: Index to Excel VBA Code; Index to Excel Freebies; Lesson 1 - Excel Fundamentals; Index to how to… providing a range of solutions


Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.


stars (0 Reviews)