Delete cell contents

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

Could someone please provide some VBA code that will delete all cell
contents for all the unlocked cells in a sheet?

Rob
 
Sub rob()
For Each r In ActiveSheet.UsedRange
If r.Locked Then
Else
r.ClearContents
End If
Next
End Sub
 
Thankyou so much. Worked perfectly.

As an alternative for another application I have, could you also provide me
with the code to have cells only cleared from a specified range instead of
the whole sheet?

Rob
 
Sub rob()
For Each r In Selection
If r.Locked Then
Else
r.ClearContents
End If
Next
End Sub

In this version, just Select the area you wish to clear before running the
macro.
 
Thanks again and that is useful, but could you please provide code that will
do a predefined range, such as A5:G200

Rob
 
And....
the condition that only the unlocked cells be cleared in the predefined
range still need to apply.

Rob
 
Change this:
For Each r In Selection
to
For Each r In activesheet.range("a5:g200").cells
 

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