Removing Formula from Excel Blank Cells automatically

Copper Contributor

Hello. I have a code that I found on the Internet for removing formula from excel blank cells but it works only for one worksheet with a specific name. I was wondering if someone could change it so it will work for several sheets with different names and ranges. For example sheetA range(a1:b20) , sheetB range(a1:e40), sheetC range(a1:n15)

THANKS.

 

Sub Macro1()

 

For Each c In Worksheets("your sheet name").Range("your range")

If c.Value = "" Then c.Select: Selection.ClearContents
Next c

End Sub

4 Replies

@Edrisbas 

Hi, I hope that I have understood the task correctly.

try this..

 

Sub RemoveFormulasFromEmptyCells()
Dim wkstab As Worksheet
Dim rngCell As Range

For Each wkstab In Worksheets

For Each rngCell In wkstab.UsedRange

If rngCell.HasFormula And rngCell.Value = "" Then
rngCell.ClearContents
End If

Next rngCell

Next wkstab

End Sub

 

Regards

Bernd

www.vba-Tanker.com - a database full of excel-macros

@Berndvbatanker 

Thanks for the response. I tried but it doesn't work. there's an error with this line:

If rngCell.HasFormula And rngCell.Value = "" Then

 

@Edrisbas 

could you append your file, please?

@Berndvbatanker 

I'm sorry the file doesn't belong to me so I don't have the right. It's weird it works but it shows me error number 13 at the end. But anyway it doesn't solve my problem because when I save the file as tab delimited or CSV there are the sign ; in the blank cells containing formulas.