problems deleting rows

ces005

Board Regular
Joined
Mar 13, 2006
Messages
189
Hi,

Here is my code:

Code:
   Rw = Range("A65536").End(xlUp).Row
   Counter = 2
   Do Until Counter > Rw
      If (Cells(Counter, LastCol).Value = False) Then
         Rows(Counter).Delete
      End If
      Counter = Counter + 1
   Loop

I see the code executing the Delete command but I still see some of the rows still remaining in the table (e.g. if delete is called 5 times, I only see 3 rows being deleted).

The last column has the value "TRUE" or "FALSE". I am trying to delete all rows in the table where the last column value is "FALSE". I am not filtering on last column being FALSE value and deleting what is shown because I don't want to delete the first row (since I want to pivot on this value). Any advice?

-Eileen
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
how about reversing the loop?
Code:
rw = Range("A65536").End(xlUp).Row
   Counter = rw
   Do Until Counter < 2
      If (Cells(Counter, LastCol).Value = False) Then
         Rows(Counter).Delete
      End If
      Counter = Counter - 1
   Loop
 
Upvote 0
Also wit h Autofilter..

Code:
With Range(Cells(1, LastCol), Cells(Cells(Rows.Count, "A").End(xlUp).Row, LastCol))
    .AutoFilter field:=1, Criteria1:="FALSE"
    .Offset(1, 0).Resize(.Rows.Count - 1, 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    .AutoFilter
End With
 
Upvote 0
Hi Kris,

Reversing the logic seems to have fixed the problem, although I don't understand why. Thanks for the help.

-Eileen
 
Upvote 0

Forum statistics

Threads
1,221,523
Messages
6,160,319
Members
451,637
Latest member
hvp2262

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top