I want to use if
condition to perform ClearContents
task. Please find my below code for the same. I written below 2 code's, but both are unsuccessful.
First Try
t = 1
Do While Cells(t, 1) <> ""
If Cells(t, 1) <> "=" Then
Cells(t, 1).ClearContents
End If
t = t + 1
Loop
Second Try
t = 1
Do While Cells(t, 1) <> ""
If Cells(t, 1) <> Formula Then
Cells(t, 1).ClearContents
End If
t = t + 1
Loop
Basically, I don't want to delete the cells contain where formulas are available but I want to delete the other data.
As an alternative, there is a method to select all the cells containing constant (non-formula) values.
Cells.SpecialCells(xlCellTypeConstants, 23).ClearContents
Faster than iterating all the cells.
Or to do this only on a specific range or the current selection, replace Cells
with Range("A1:A100")
or Selection
.
(In Excel, you can find this under Home -> Editing -> Find & Select -> Go to Special. Here you can have Excel automatically select only the Constants or the Formulas inside the existing selection.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With