Macro to clear cells

  • Thread starter Thread starter Glenn Robertson
  • Start date Start date
G

Glenn Robertson

Hi,

I am trying to put a macro button on a spreadsheet, that
when clicked by the user it will delete all information
from cells that are unprotected on the sheet. Is this
possible.

Many Thanks

Glenn
 
Try this for the activesheet Glenn

Sub test()
Dim cell As Range
For Each cell In ActiveSheet.UsedRange
If cell.Locked = False Then cell.ClearContents
Next
End Sub
 
I have tried this and it works to an extent. I have some
merged fields on my spreadsheet and when i run the macro
it clears the cells but i get an error.

Run-time error '1004':
Cannot change part of a merged cell.

If the merged cell is unprotected I would like it cleared
with the other cells when the macro is pushed. ???

Thanks, Glenn
 
Back
Top