MACRO HELP!!! I Need A Macro That Will Clear Contents On All Unlocked Cells On A Sheet (excel 2010)

Barryoffshore

Board Regular
Joined
Feb 21, 2005
Messages
73
I have about 85 sheets in a workbook that are all very different in which cells are locked and which are unlocked. I need a macro that will "Clear Contents" on all unlocked cells on a sheet. The sheets are (or will be) protected. Can someone PLEASE help me!!!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try this.
If any of the sheets are unprotected, it will kill everything on those sheets.
The .Protect line is there to prevent that.
Code:
Sub test()
    Dim oneSheet As Worksheet
    Application.DisplayAlerts = False
    On Error Resume Next
    For Each oneSheet In ThisWorkbook.Worksheets
        oneSheet.Protect
        oneSheet.Cells.Value = vbNullString
    Next oneSheet
    On Error GoTo 0
    Application.DisplayAlerts = True
End Sub
 
Upvote 0
Try this on a copy of the workbook:

Code:
Sub ClearUnlocked()
    Dim wks         As Worksheet

    On Error Resume Next
    For Each wks In Worksheets

        With wks
            If Not .ProtectContents Then
                .Protect
                .UsedRange.Value = ""
                .Unprotect
            Else
                .UsedRange.Value = ""
            End If
        End With
    Next wks
End Sub
 
Upvote 0
Mr. mikerickson

THANK YOU VERY VERY MUCH!!! This worked to clear the workbook, which is also what I needed! You have a knowledge of excel that astounds me!!! Thank you again, very much!
 
Last edited:
Upvote 0
shg - THANK YOU VERY MUCH!!! This works to clear each sheet, which is EXACTLY what I needed! I wish I had even a small amount of the knowledge you have! Thank you again, very much!

Try this on a copy of the workbook:

Code:
Sub ClearUnlocked()
    Dim wks         As Worksheet

    On Error Resume Next
    For Each wks In Worksheets

        With wks
            If Not .ProtectContents Then
                .Protect
                .UsedRange.Value = ""
                .Unprotect
            Else
                .UsedRange.Value = ""
            End If
        End With
    Next wks
End Sub
 
Upvote 0
SHG & MIKERICKSON

Is there a macro that will clear ONLY the sheet I am in at the time? I thank y'all both very VERY much for all your help!!!





shg - THANK YOU VERY MUCH!!! This works to clear each sheet, which is EXACTLY what I needed! I wish I had even a small amount of the knowledge you have! Thank you again, very much!
 
Upvote 0
Just eliminate the loop in the previous macro
Code:
Sub test()
   
    Application.DisplayAlerts = False
    On Error Resume Next
    
    ActiveSheet.Protect
    ActiveSheet.Cells.Value = vbNullString
    
    On Error GoTo 0
    Application.DisplayAlerts = True
End Sub
 
Upvote 0
Mr. "Mikerickson", I can't thank you enough!!! You are just too smart - I wish I had just a fraction of your knowledge of excel!

Again... THANK YOU!!! THANK YOU!!! THANK YOU!!!



Just eliminate the loop in the previous macro
Code:
Sub test()
   
    Application.DisplayAlerts = False
    On Error Resume Next
    
    ActiveSheet.Protect
    ActiveSheet.Cells.Value = vbNullString
    
    On Error GoTo 0
    Application.DisplayAlerts = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,049
Messages
6,122,864
Members
449,097
Latest member
dbomb1414

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