Macro: Clear contents of unlocked cells

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi everybody
I´ve just pasted the following macro and run it within my worksheet, but an
error displays as I have merged cells.

Should I consider some additional sentence for that?? (I don't know how
works VBA).

Sub rob()
For each r in activesheet.range("C7:h29").cells
if r.locked then
else
r.clearcontents
end if
Next
End sub

Thank you in advance
 
Sub rob()
For each r in activesheet.range("C7:h29").cells
if r.locked then
else
r.MergeArea.clearcontents
end if
Next
End sub
 
Tuckland

Just a point this macro doesn't clear the content of unlocked cells. What it
does is look if the cell would be locked if the sheet was protected. i.e it
looks if the locked box is checked in Format|Cells|protection.

Mike
 
Instead of
r.clearcontents
try
r.value = ""


Hi everybody
I´ve just pasted the following macro and run it within my worksheet, but an
error displays as I have merged cells.

Should I consider some additional sentence for that?? (I don't know how
works VBA).

Sub rob()
For each r in activesheet.range("C7:h29").cells
if r.locked then
else
r.clearcontents
end if
Next
End sub

Thank you in advance
 
Sorry for not answer you before...
I have checked the macro and as you say it doesn't cover what I really need
:-(
 

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