Clearing Constant Cells

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
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
What happens if you remove all those selects and put in error handling i.e.

Code:
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
        On Error Resume Next
        Range("A4:Z10000").SpecialCells(xlCellTypeConstants, 23).ClearContents
        On Error GoTo 0
        ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
                                                                             , AllowFormattingCells:=True, AllowInsertingColumns:=True, _
                            AllowInsertingRows:=True, AllowFiltering:=True

    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,497
Messages
6,125,157
Members
449,208
Latest member
emmac

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top