The Animal
Active Member
- Joined
- May 26, 2011
- Messages
- 449
Hi
I have the below to 'Clear" the cell data but ignoring cells with formula from cells A4:Z10000. It work fine when you run the macro once (when cells have data) but if you try to run again then hangs up on below "Selection Line" (in red below). If you then add any data at all in a cell anywhere from A4:Z10000 it will then run OK. How would it look if I want to run macro again without having to add any data.
Thanks for any help Stephen
Sub ClearConstantsA4toZ10000()
If MsgBox("Are you ABSOLUTLY sure? (1) This action will DELETE all Data from Row 4 to 10000 THIS ACTION CANNOT BE UNDONE", vbYesNoCancel) = vbYes Then
ActiveSheet.Unprotect
Range("A4:Z10000").Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
Selection.ClearContents
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowInsertingColumns:=True, _
AllowInsertingRows:=True, AllowFiltering:=True
End If
End Sub
I have the below to 'Clear" the cell data but ignoring cells with formula from cells A4:Z10000. It work fine when you run the macro once (when cells have data) but if you try to run again then hangs up on below "Selection Line" (in red below). If you then add any data at all in a cell anywhere from A4:Z10000 it will then run OK. How would it look if I want to run macro again without having to add any data.
Thanks for any help Stephen
Sub ClearConstantsA4toZ10000()
If MsgBox("Are you ABSOLUTLY sure? (1) This action will DELETE all Data from Row 4 to 10000 THIS ACTION CANNOT BE UNDONE", vbYesNoCancel) = vbYes Then
ActiveSheet.Unprotect
Range("A4:Z10000").Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
Selection.ClearContents
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowInsertingColumns:=True, _
AllowInsertingRows:=True, AllowFiltering:=True
End If
End Sub