Dana DeLouis said:
This idea looks to see if there are any Precedents within the formula.
Sub Demo() ...
If Rng.Precedents.Count > 0 Then
If Err.Number = 1004 Then 'No cells were found.
Rng.Clear
Err.Clear
End If
End If
...
OP's specs may be incomplete. Should cells containing formulas like =NOW()
or =RAND() be deleted? Your macro deletes them. It also deletes DDE
formulas
and cells containing external references into closed workbooks when there
are no references to ranges in the formula's parent workbook.
If only cells containing formulas involving only operations with constant
operands should be deleted, then maybe something like
Sub foo()
Const RE_DQS As String = """[^""]*(""""[^""]*)*"""
Const RE_TKN As String = "\b[_A-Za-z]"
Dim rng As Range, r As Range, ws As Worksheet
Dim re As Object, rf As String
Set re = CreateObject("VBScript.RegExp")
re.Global = True
re.IgnoreCase = False
For Each ws In ActiveWorkbook.Worksheets
On Error GoTo Continue
Set rng = ws.UsedRange.SpecialCells(xlCellTypeFormulas)
On Error GoTo 0
For Each r In rng
rf = r.Formula
re.Pattern = RE_DQS
rf = re.Replace(rf, """""") 'reduce all string constants
re.Pattern = RE_TKN
If Not re.Test(rf) Then r.Clear
Next r
Continue:
Err.Clear
Next ws
End Sub