Code to delete row when certain criteria met

midoop

New Member
Joined
Aug 9, 2013
Messages
37
Hello Again Forum,

I am trying to delete rows when ever a cell in column G says "No Data" and a cell on the same row in column E is blank.

Below is my code:

Code:
lRow = Cells(Rows.Count, "A").End(xlUp).Row
Do While lRow > 0
If Cells(lRow, 7) = "No Data" And Cells(lRow, 5) = "" Then
Rows(lRow).Delete Shift:=xlUp
End If
lRow = lRow - 1
Loop
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
That would mean none of the rows met the criteria.

And the criteria is
The value in G = "No Data" AND The value in E is ""
perhaps you actually mean OR instead of AND


Also, note that VBA is case sensitive.
So if the cell is "no data", then it will not be counted as "No Data"

Try
If Ucase(Cells(lRow, 7)) = "NO DATA" And Cells(lRow, 5) = "" Then
 
Upvote 0
I mean AND
And I tried If Ucase(Cells(lRow, 7)) = "NO DATA" And Cells(lRow, 5) = "" Then and I got the same thing.
Then I deleted the And Cells(lRow, 5) = "" part, and same thing. The column is formatted as general and i tried converting it to text and that did not help. It just skipped that part altogether.
 
Upvote 0
I got it to work using the code below:

Code:
With ws1.Columns("A:I").Resize(ws1.UsedRange.Rows.Count)
.AutoFilter 7, "No Data"
With .Offset(1).SpecialCells(xlCellTypeVisible)
.AutoFilter 5, ""
With .Offset(1).SpecialCells(xlCellTypeVisible)
.EntireRow.Delete
End With
.AutoFilter
End With
.AutoFilter
End With
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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