clear contents cells of unprotected cells

G

Guest

Hi. I am trying to clear the contents of all unprotected cells only on a
protected worksheet. Any ideas how to do it without giving the absolute cell
reference for each of the unprotected cells I want to clear?
 
V

Vasant Nanavati

Something like:

Sub Test()
Dim c As Range
For Each c In ActiveSheet.UsedRange.Cells
If Not c.Locked Then c.ClearContents
Next
End Sub
 
T

Tom Ogilvy

for each cell in activesheet.UsedRange
if cell.locked = false then
cell.Clearcontents
end if
Next
 
G

Guest

Thanks, it worked!

Vasant Nanavati said:
Something like:

Sub Test()
Dim c As Range
For Each c In ActiveSheet.UsedRange.Cells
If Not c.Locked Then c.ClearContents
Next
End Sub
 
G

Guest

Tom,

I've implemented the code you supplied for Ed, however, some of the cells
involved are merged and Error 1004 appears and says "Cannot change part of a
merged cell". Any ideas?

Thanks in advance!
 
D

Dave Peterson

change:

cell.Clearcontents
to
cell.value = ""


Tom,

I've implemented the code you supplied for Ed, however, some of the cells
involved are merged and Error 1004 appears and says "Cannot change part of a
merged cell". Any ideas?

Thanks in advance!
 

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

Top