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

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

agihcam

Well-known Member
Joined
Jan 16, 2006
Messages
1,624
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
 

Krishnakumar

Well-known Member
Joined
Feb 28, 2003
Messages
2,615
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
 

ces005

Board Regular
Joined
Mar 13, 2006
Messages
189
Hi Kris,

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

-Eileen
 

Forum statistics

Threads
1,141,841
Messages
5,708,911
Members
421,598
Latest member
NewHere

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
Top