MAcro to Clear Cells

G

Glenn Robertson

Hi,

I have a macro that when pushed it will clear all the info
out of any cell that is un-protected on my worksheet. The
macro works fine until it comes across a merged cell then
I get the following error message :-

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

My macro is as follows :-

Sub test()
Dim cell As Range
For Each cell In ActiveSheet.UsedRange
If cell.Locked = False Then cell.ClearContents
Next
End Sub

Can anybody help ?
 
H

Harald Staff

Sub test()
Dim cell As Range
For Each cell In ActiveSheet.UsedRange
If cell.Locked = False Then cell.MergeArea.ClearContents
Next
End Sub
 
R

Ron de Bruin

Sorry Glenn I did not give a answer on this in the original thread
I am building a network at home and format all the PC's so I lost the thread
 

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