Delete row if

Doedtman

Board Regular
Joined
May 21, 2010
Messages
92
Hello!
I'm trying to delete all rows with "Yes" in column G, but for some reason it doesn't work. Would anyone have suggestions to help me fix this coding?

Code:
Dim rng As Range
Set rng = Sheets("Summary").Range("G3:G8000")
Dim c As Range
 For Each c In rng
    If c = "Yes" Then
        c.EntireRow.Delete
    End If
    Next c
End Sub


Thanks!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

BarryL

Well-known Member
Joined
Jan 20, 2014
Messages
1,436
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
you need to go backwards

Code:
Sub test()
Dim rng As Range
Set rng = Sheets("Summary").Range("G3:G8000")
Dim c As Long
 For c = 8000 To 3 Step -1
    If Cells(c, 7).Value = "Yes" Then
        Rows(c).EntireRow.Delete
    End If
    Next c
End Sub
 
Upvote 0

MattH1

Board Regular
Joined
Jul 15, 2016
Messages
174
Is your range set as 3 to 8000?

Here's how I would approach it, though there may be a better way to do this:

Code:
Sub Doedtman()

Dim RowCount as Long
RowCount = Sheets("Summary").Cells(ActiveSheet.Rows.Count, "G").End(xlUp).Row

Sheets("Summary").Activate

For I = RowCount to 3 Step -1
If Cells(I,7) = "Yes" Then Cells(I,7).EntireRow.Delete
Next I

End Sub

Let me know if this works. I haven't tested it myself but it seems to be workable.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,190,631
Messages
5,982,031
Members
439,750
Latest member
megaman777

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