Macro to delete all unlocked cells in workbook

hnswart

New Member
Joined
Aug 23, 2014
Messages
9
Can anyone help me with a macro to cycle through my entire workbook and clear all the unlocked cells.

Many thanks.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
How about

VBA Code:
Sub ClearCells()
  Dim c As Range, sh As Worksheet
  Application.ScreenUpdating = False
  For Each sh In Sheets
    For Each c In sh.UsedRange
      If Not c.Locked Then c.ClearContents
    Next
  Next
End Sub
 
Upvote 0
How about

VBA Code:
Sub ClearCells()
  Dim c As Range, sh As Worksheet
  Application.ScreenUpdating = False
  For Each sh In Sheets
    For Each c In sh.UsedRange
      If Not c.Locked Then c.ClearContents
    Next
  Next
End Sub
Thank you.
I tried this macro but excel freezes when i run it.
 
Upvote 0
How about
VBA Code:
Sub hnswart()
   Dim Ws As Worksheet
   
   With Application.FindFormat
      .Clear
      .Locked = False
   End With
   For Each Ws In Worksheets
      Ws.UsedRange.Replace "*", "", , , , , True, False
   Next Ws
   Application.FindFormat.Clear
End Sub
 
Upvote 0
Solution
Sub hnswart() Dim Ws As Worksheet With Application.FindFormat .Clear .Locked = False End With For Each Ws In Worksheets Ws.UsedRange.Replace "*", "", , , , , True, False Next Ws Application.FindFormat.Clear End Sub
That worked perfectly. Thank you very much
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
How about
VBA Code:
Sub hnswart()
   Dim Ws As Worksheet
  
   With Application.FindFormat
      .Clear
      .Locked = False
   End With
   For Each Ws In Worksheets
      Ws.UsedRange.Replace "*", "", , , , , True, False
   Next Ws
   Application.FindFormat.Clear
End Sub


Tried to use this one as well as some others, but i keep getting the same response. Please help!!
 

Attachments

  • Screenshot 2021-04-23 183832.png
    Screenshot 2021-04-23 183832.png
    21.2 KB · Views: 20
Upvote 0
Remove the first line that is in blue !
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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