For Each Loop to Delete row w/ value (Loop Backwards)?

DougStroud

Well-known Member
Joined
Aug 16, 2005
Messages
2,976
Office Version
  1. 365
Platform
  1. MacOS
I am just curious if a For Each loop can be instructed to loop starting the bottom of the range. I know that a For To Loop can handle looping from the bottom up, just wondering if this is possible?

Code:
Sub Filterout()
Dim c As Range
Dim rng As Range
Dim i As Long
Dim lrow As Long
Dim counter As Integer
lrow = Cells(Rows.Count, 3).End(xlUp).Row
Set rng = Range("c2:c36")

For Each c In rng
If Left(c.Value, 1) <> "~~" Then
c.EntireRow.Delete
End If
Next c
 
This does not involve a loop, but perhaps you would like to check the run-time using a different approach :-

Code:
Sub Filterout()
Dim rng As Range
[C:C].Insert
Set rng = [C2:C15500]
With rng
    .FormulaR1C1 = "=if(rc[1]<>""~~"",""d"",1)"
    .Value = .Value
    .EntireRow.Sort Key1:=[C1], Order1:=xlAscending, Header:=xlNo
    On Error Resume Next
    .SpecialCells(xlCellTypeConstants, 2).EntireRow.Delete
    On Error GoTo 0
    .EntireColumn.Delete
End With
End Sub

Try testing where every other line starts with ~~
 
Upvote 0

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".

Forum statistics

Threads
1,224,804
Messages
6,181,056
Members
453,015
Latest member
ZochSteveo

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