Clearing Unprotected Cells

P

Phil Hageman

What would the macro code be to clear all unprotected
cells in the current worksheet? Would put this macro in
Personal.xls
 
T

Tom Ogilvy

for each cell in Activesheet.UsedRange
if not cell.Locked then
cell.clearcontents
end if
Next


or assuming you wouldn't clear formulas


for each cell in Activesheet.UsedRange.SpecialCells(xlconstants)
if not cell.Locked then
cell.clearcontents
end if
Next
' or if you would add
for each cell in Activesheet.UsedRange.SpecialCells(xlformulas)
if not cell.Locked then
cell.clearcontents
end if
Next
 
P

Phil Hageman

Thanks again, Tom
-----Original Message-----
for each cell in Activesheet.UsedRange
if not cell.Locked then
cell.clearcontents
end if
Next


or assuming you wouldn't clear formulas


for each cell in Activesheet.UsedRange.SpecialCells (xlconstants)
if not cell.Locked then
cell.clearcontents
end if
Next
' or if you would add
for each cell in Activesheet.UsedRange.SpecialCells (xlformulas)
if not cell.Locked then
cell.clearcontents
end if
Next
--
Regards,
Tom Ogilvy




.
 
P

Phil Hageman

Tom, a wrinkle - getting: Run-time error '1004': Cannot
change part of a merged cell. "If not..." line yellow.
What next?

Thanks, Phil
 
D

Dave Peterson

You could do it for just the first cell in the mergearea or even simpler:

cell.value = ""
instead of
cell.clearcontents
 
T

Tom Ogilvy

for each cell in Activesheet.UsedRange
if not cell.Locked then
cell.MergeArea.clearcontents
end if
Next
 
P

Phil Hageman

Thanks, Tom - works great. To speed things up, I took a
line from something you gave me earlier:
Application.ScreenUpdating = False/True

Thanks again.
 

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