happydonut
Board Regular
- Joined
- Nov 28, 2019
- Messages
- 57
- Office Version
- 365
- Platform
- Windows
Hi all,
I have a Macro that clear contents in some cells in different sheets. It looks something like this:
2 problems/requests
- I want that if there is nothing to clear from these cells, to add a MsgBox saying "Nothing to clear".
- Also, now I get an error if there is nothing to clear and the sheet protection disables.
Cheers.
Edit: Also, if cells mentioned in the range above are partially populated, I still get the same error message which I want to avoid.
I have a Macro that clear contents in some cells in different sheets. It looks something like this:
VBA Code:
Sub sbClearCellsOnlyData()
ActiveSheet.Unprotect
If MsgBox("Are you sure?", vbYesNo) = vbNo Then Exit Sub
Worksheets("R").Range("C2:D2, A6:C6").SpecialCells(xlCellTypeConstants).ClearContents
Worksheets("SA").Range("A2:A18, A22:B22").SpecialCells(xlCellTypeConstants).ClearContents
Worksheets("T").Range("A3:CE325").SpecialCells(xlCellTypeConstants).ClearContents
ActiveSheet.Protect
End Sub
2 problems/requests
- I want that if there is nothing to clear from these cells, to add a MsgBox saying "Nothing to clear".
- Also, now I get an error if there is nothing to clear and the sheet protection disables.
Cheers.
Edit: Also, if cells mentioned in the range above are partially populated, I still get the same error message which I want to avoid.