View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Stefi Stefi is offline
external usenet poster
 
Posts: 2,646
Default Delete contents unlocked cells

You didn't post which line causes the error! Anyway try this version, it
will work on the whole active sheet:

Sub delunlocked()
Dim aktter As Range, acell As Range
Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlValues, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Activate
Set aktter = Range("A1", ActiveCell)
For Each acell In aktter
If Not acell.Locked Then acell.ClearContents
Next acell
End Sub

Which Excel version do you use?

Stefi


RobN ezt *rta:

Thanks Stefi,

But this comes up with a runtime error 1004.

Do I need to select a range or something or will this do the whole active
sheet?

Rob

"Stefi" wrote in message
...
Try this:
Sub delunlocked()
Dim aktter As Range, acell As Range
Set aktter = Selection.CurrentRegion
For Each acell In aktter
If Not acell.Locked Then acell.ClearContents
Next acell
End Sub

Regards,
Stefi


"RobN" ezt *rta:

Could someone please provide me with some code to clear contents of all
unlocked cells in a worksheet?

Rob