clear cells macro

D

Dorothy

I am looking to set up a clear button on sheet 1 that when clicked on will
clear various cells on sheet two.

I have a clear button on sheet 1 that when clicked clears cells on sheet 1
that reads;
Range("A1:A77").ClearContents

but when I try to put that cammand button on page one to clear cells on page
two I can't get the proper script that works.

any help is appreciated.

Dorothy
 
D

Dorothy

To be more specific, I am trying to get a clear button on page one that when
clicked will clear all unprotected cells on pages 2, 3 and 4
 
M

Michael M

Dorothy
If it is a Non Contigious range try
Worksheets("Sheet2").Range("A1;A77;B6;D15;G5").ClearContents

etc,etc,

HTH
Michael M
 
G

Gord Dibben

Sub UnLocked_Cells()
Dim cell As Range, tempR As Range, rangeToCheck As Range
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Sheets(Array _
("Sheet2", "Sheet3", "Sheet4"))
ws.Activate
For Each cell In ActiveSheet.UsedRange
If Not cell.Locked Then
cell.ClearContents
End If
Next cell

Next ws
End Sub

You should get used to referring to worksheets as "sheets" rather than "pages"
which is generally used to designate printed sheets of paper.


Gord Dibben MS Excel MVP
 
D

Dave Peterson

But don't use semicolons.

Worksheets("Sheet2").Range("A1,A77,B6,D15,G5").ClearContents
or maybe
Worksheets("Sheet2").Range("A1:A77,B6:D15,G5").ClearContents
 

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