Question Details

No question body available.

Tags

excel vba

Answers (1)

May 13, 2026 Score: 6 Rep: 31,621 Quality: High Completeness: 60%

You can check if a cell contains a formula that is dependent on other cells using the property Precedents. If the cell contains a formula that is dependent on any other cell, this property will return a Range containing all of those cells. However, accessing this property for a cell that is not depending on any other cell value will give a runtime error, so you have to enclose the statement with an On Error-statement.

So to clear all cells containing a formula without dependencies, fetch all cells with a formula and then loop over all cells and check the Precedents:

Sub ClearDummyFormulas(rangeToClear As Range)
    ' Get all Cells containing a formula
    On Error Resume Next
    Dim formulaRange As Range, cell As Range
    Set formulaRange = rangeToClear.SpecialCells(xlCellTypeFormulas)
    On Error GoTo 0
    If formulaRange Is Nothing Then Exit Sub

' For every cell, check if formula is dependent on any other cell For Each cell In formulaRange Dim dependencies As Range Set dependencies = Nothing On Error Resume Next Set dependencies = cell.Precedents On Error GoTo 0 ' Not dependent on other cells, clear it. If dependencies Is Nothing Then cell.ClearContents Next cell End Sub

For those who are interested: There is a counterpart to the Precedents-Method: To get a list of cells that are depending on a cell, use the property Dependents