Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Special Cells to Loop back

I've read (in the forums) that it is best to delete from
bottom up and I use this technique, however I'm having a
bit of trouble setting up a for loop for one of my lists.

I have a filtered list and have been looping through the
code (from top to bottom) by the following.

'Row one is the header row
intFrstRow = Range("A1").End(xlDown).Row
intLastRow = Range("A" & intFrstRow).End(xlDown).Row

'Create range
Range("A" & intFrstRow &, "A" & intLastRow).SpecialCells
(xlCellTypeVisible).Select

I tried setting the range the other way (intLastRow,
intFirstRow) but that didn't help.

The only method I can think of (one given by a helpful
MVP) is using a do loop to start at the end and count
backwards until hits a visible row.
Is there a faster method than this?

Thanks
Hafeez Esmail
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Special Cells to Loop back

One way:

This sets up a range of rows to delete, then deletes all the
unwanted lines at once:


Dim rDelete As Range
Dim rCell As Range
On Error Resume Next 'in case no visible cells
For Each rCell In Range("A2:A" & Range("A" & _
Rows.Count).End(xlUp).Row).SpecialCells(xlCellType Visible)
If rCell.Value = 1 Then 'or whatever criteria you use
If rDelete Is Nothing Then
Set rDelete = rCell
Else
Set rDelete = Union(rDelete, rCell)
End If
End If
Next rCell
On Error GoTo 0
If Not rDelete Is Nothing Then rDelete.EntireRow.Delete



In article ,
"Hafeez Esmail" wrote:

I've read (in the forums) that it is best to delete from
bottom up and I use this technique, however I'm having a
bit of trouble setting up a for loop for one of my lists.

I have a filtered list and have been looping through the
code (from top to bottom) by the following.

'Row one is the header row
intFrstRow = Range("A1").End(xlDown).Row
intLastRow = Range("A" & intFrstRow).End(xlDown).Row

'Create range
Range("A" & intFrstRow &, "A" & intLastRow).SpecialCells
(xlCellTypeVisible).Select

I tried setting the range the other way (intLastRow,
intFirstRow) but that didn't help.

The only method I can think of (one given by a helpful
MVP) is using a do loop to start at the end and count
backwards until hits a visible row.
Is there a faster method than this?

Thanks
Hafeez Esmail

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Special Cells to Loop back

Dim rng as Range
set rng = ActiveSheet.Autofilter.Range.Columns(1)
' exclude the header row
set rng = rng.offset(1,0).Resize(rng.rows.count-1)
rng.SpecialCells(xlvisible).Select

--
Regards,
Tom Ogilvy

"Hafeez Esmail" wrote in message
...
I've read (in the forums) that it is best to delete from
bottom up and I use this technique, however I'm having a
bit of trouble setting up a for loop for one of my lists.

I have a filtered list and have been looping through the
code (from top to bottom) by the following.

'Row one is the header row
intFrstRow = Range("A1").End(xlDown).Row
intLastRow = Range("A" & intFrstRow).End(xlDown).Row

'Create range
Range("A" & intFrstRow &, "A" & intLastRow).SpecialCells
(xlCellTypeVisible).Select

I tried setting the range the other way (intLastRow,
intFirstRow) but that didn't help.

The only method I can think of (one given by a helpful
MVP) is using a do loop to start at the end and count
backwards until hits a visible row.
Is there a faster method than this?

Thanks
Hafeez Esmail



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Special Cells to Loop back

Thanks guys :-)
You're the best!

-----Original Message-----
Dim rng as Range
set rng = ActiveSheet.Autofilter.Range.Columns(1)
' exclude the header row
set rng = rng.offset(1,0).Resize(rng.rows.count-1)
rng.SpecialCells(xlvisible).Select

--
Regards,
Tom Ogilvy

"Hafeez Esmail" wrote in message
...
I've read (in the forums) that it is best to delete from
bottom up and I use this technique, however I'm having a
bit of trouble setting up a for loop for one of my

lists.

I have a filtered list and have been looping through the
code (from top to bottom) by the following.

'Row one is the header row
intFrstRow = Range("A1").End(xlDown).Row
intLastRow = Range("A" & intFrstRow).End(xlDown).Row

'Create range
Range("A" & intFrstRow &, "A" & intLastRow).SpecialCells
(xlCellTypeVisible).Select

I tried setting the range the other way (intLastRow,
intFirstRow) but that didn't help.

The only method I can think of (one given by a helpful
MVP) is using a do loop to start at the end and count
backwards until hits a visible row.
Is there a faster method than this?

Thanks
Hafeez Esmail



.

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
compare cells, copy, loop Immortal_Creations Excel Worksheet Functions 2 July 17th 09 03:34 PM
How do I loop a range of cells until I get a numeric value? ManKind New Users to Excel 1 June 4th 06 06:48 AM
HOW-TO? Loop through cells in a column Mr. Clean[_2_] Excel Programming 4 December 12th 03 08:28 PM
VBA loop cells Adrie Rahanra Excel Programming 1 September 30th 03 10:22 AM
How to loop through cells in macro Andrew[_21_] Excel Programming 1 September 8th 03 08:21 PM


All times are GMT +1. The time now is 10:05 AM.

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

About Us

"It's about Microsoft Excel"