View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default delete contents of visible cells only

Hi Michael,

Try:

'=============
Public Sub Tester()
On Error Resume Next
Range("A1:D10").SpecialCells(xlCellTypeVisible). _
ClearContents
On Error GoTo 0
End Sub
'<<=============


---
Regards,
Norman



"michael.beckinsale" wrote in message
oups.com...
Hi All,

I would like to loop thru a range of cells and delete the contents of
the visible cells only.

eg if the range is A1:D10 and column B is hidden all the cells will be
deleted except B1:B10

I tried the following but the code fails where indicated.

Sub testdelete()

Dim rng As Range
Dim mycell

Set rng = Sheet1.Range("A1:D10")

For Each mycell In rng
If mycell.Hidden = False Then fails here
mycell.Delete
End If
Next mycell

End Sub

Can anybody help please?

Regards

Michael Beckinsale