Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear only cells containing formulas

I need a VBA code that clears only cells containing formulas and skip cells containing values in a given Excel Worksheet. I have the following Code:

Dim rng As Range, cl As Range
Set rng = ThisWorkbook.Sheets("MATRIX").Range("C2:AU10000")
    For Each cl In rng
        If cl.Hyperlinks = .Hyperlinks Then
            cl.ClearContents
        End If
    Next cl
like image 597
Souza Saulo Avatar asked Mar 30 '26 22:03

Souza Saulo


2 Answers

Try this approach, please:

If cl.HasFormula Then
       cl.ClearContents
End If
like image 171
FaneDuru Avatar answered Apr 02 '26 10:04

FaneDuru


This should be the quickest way

rng.SpecialCells(xlCellTypeFormulas).ClearContents
like image 28
Storax Avatar answered Apr 02 '26 12:04

Storax