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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top