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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
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
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,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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