Hello,
I have a macro for clearing contents after copying first sheet and creating new ones. VBA code is for clearing contents, but to leave all formulas within range intact.
Code is :
Sub delete_cells()
Dim lngCounter As Long
Dim rConstants As Range
For lngCounter = 2 To 13
Set rConstants = Sheets(lngCounter).Range("E3:AI318").SpecialCells(xlCellTypeConstants)
rConstants.ClearContents
Next lngCounter
End Sub
Code works when there are actually some cells to clear, but If none (cells are clear - except formula cells) I receive error "no cells were found". How can I fix that, I want this code only to delete cells If user accidently types something in first sheet which is being copied.
Tried this but not working :
Sub delete_cells()
Dim lngCounter As Long
Dim rConstants As Range
For lngCounter = 2 To 13
Set rConstants = Sheets(lngCounter).Range("E3:AI318").SpecialCells(xlCellTypeConstants)
If rConstants <> "" Then
rConstants.ClearContents
End If
Next lngCounter
End Sub
Bookmarks