PDA

View Full Version : [SOLVED] Deleting rows based on values of cells in TWO different columns



clggmu
07-12-2016, 08:18 AM
Hi there, I am looking to delete rows that do not contain "ECB account of monetary policy meeting" in column E and contain the value zero in column F. I.e if the value in column E is equal to "ECB account of monetary policy meeting" and column F is equal to 0 then keep - however if column E does not contain "ECB account...." and column F is equal to 0 then delete all rows where this is true. This is the code I'm using but it is just deleting every row where column F = 0, including the rows where cells in row E contain the ECB value




'Get the last row and column B
finalRow = Cells(1000, 2).End(xlUp).row
'Loop through data backwards
For i = finalRow To 1 Step -1
'Do your check
If (Cells(i, 5) <> "ECB account of monetary policy meeting" And Cells(i, 6) = 0) Then
'Delete the row if criteria met
Cells(i, 1).EntireRow.Delete
End If
Next i

mdmackillop
07-12-2016, 08:55 AM
Try

If Trim((Cells(i, 5)) <> "ECB account of monetary policy meeting" And Cells(i, 6) = 0) Then

clggmu
07-13-2016, 12:22 AM
That worked perfect thanks!