View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default delete all but protected cells

King

Sub UnLocked_Cells()
Dim cell As Range, tempR As Range, rangeToCheck As Range
'rotate through all cells in the selection
For Each cell In Intersect(Selection, ActiveSheet.UsedRange)
If Not cell.Locked Then
'add to tempR if unprotected
If tempR Is Nothing Then
'do it this way for the first unprotected cell
Set tempR = cell
Else
'add subsequent cells this way.
Set tempR = Union(tempR, cell)
End If
End If
Next cell
'do this upon completion of the For..Next checking
If tempR Is Nothing Then
MsgBox "There are no UnLocked cells in " & _
"the selected range."
End
End If
'select qualifying cells
tempR.Select
Selection.ClearContents
End Sub

Gord Dibben Excel MVP

On Thu, 22 Jan 2004 20:25:24 -0600, Kingtriotn
wrote:

Hello,
I am trying to put together a macro to delete all but the protected
cells. Nothing I try seems to work. Has anyone done this before? It
is easy for me to turn protection on and off with a macro so shouldnt
it also be easy to delete the content of all non protected cells as
well?
Thanks in advance
Kingtriton


---
Message posted from http://www.ExcelForum.com/