Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default delete contents of visible cells only

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default delete contents of visible cells only

Sub testdelete()

Dim rng As Range
Dim mycell As Range '<--FIXED

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

For Each mycell In rng
If mycell.EntireColumn.Hidden = False Then '<--FIXED
mycell.Clearcontents '<--FIXED
End If
Next mycell

End Sub


Regards,
Stefi


€˛michael.beckinsale€¯ ezt Ć*rta:

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default delete contents of visible cells only


Stefi / Norman,

Many thanks, both work fine.

In terms of speed / efficiency which code is the best?

Regards

Michael beckinsale

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default delete contents of visible cells only

Hi Michael,

Except for ranges with a very large number of non-contiguous visible cells,
I would use the SpecialCells method.


---
Regards,
Norman



"michael.beckinsale" wrote in message
oups.com...

Stefi / Norman,

Many thanks, both work fine.

In terms of speed / efficiency which code is the best?

Regards

Michael beckinsale





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default delete contents of visible cells only

Hi Michael,

Just to add, in the case of small ranges, I would not anticipate any
perceptible difference in speed.


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Michael,

Except for ranges with a very large number of non-contiguous visible
cells, I would use the SpecialCells method.


---
Regards,
Norman



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default delete contents of visible cells only


Norman,

Thanks. I have approx 4000 cells in the range so l will go with
Cells.special method

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I only delete/clear the visible cells in a filtered list? Merv Excel Worksheet Functions 5 March 2nd 07 07:00 PM
Delete contents of cells mikespeck Excel Worksheet Functions 3 July 27th 06 03:16 PM
Delete Contents of Cells ir26121973 Excel Programming 9 April 5th 06 07:10 PM
contents in cells are not visible when word wrap is selected Steve Excel Discussion (Misc queries) 2 January 7th 06 12:36 AM
Delete specific cells contents in a row with some locked cells in the same row trussman Excel Programming 2 March 1st 05 06:12 PM


All times are GMT +1. The time now is 04:54 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"