Protected Worksheets with info that needs to be deleted.

  • Thread starter Thread starter Joe Clark
  • Start date Start date
J

Joe Clark

Excell 2003. I have a worksheet that is protected, and people are allowed to
input data in the non-protected cells. Is there any way too highlight the
whole worksheet and delete the information that is in the non-protected cells
with out deleted the formulas in the protected cells?
 
Try this

Sub ClearUnlockedCells()
Dim myRange As Range
Dim r As Range
Dim aWS As Worksheet

Set aWS = ActiveSheet

Set myRange = Nothing
For Each r In aWS.UsedRange
If Not r.Locked Then
If myRange Is Nothing Then
Set myRange = r
Else
Set myRange = Union(myRange, r)
End If
End If
Next r

If Not myRange Is Nothing Then
myRange.ClearContents
End If
End Sub
 
Back
Top