Code To remove rows with criteria

divapaxo

Board Regular
Joined
Feb 4, 2005
Messages
110
Trying to amend this code to get the following result

If column B = GBP then do not delete that row and if column A = code AL1234 and column B = EUR then do not delete the row everything else delete row.

Set ws = Sheets("EQUITY REPORT")
For lRow = ws.UsedRange.Row + ws.UsedRange.Rows.Count - 1 To 1 Step -1
v1 = ws.Cells(lRow, "D").Value
If Len(v1) > 0 _
And IsNumeric(v1) _
And Val(v1) = 0 Then
ws.Rows(lRow).Delete Shift:=xlUp
End If
Next lRow

Thanks.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try (untested):

Code:
Set ws = Sheets("EQUITY REPORT") 
For lRow = ws.UsedRange.Rows.Count To 1 Step -1 
   v1 = ws.Cells(lRow, "D").Value 
   If Len(v1) > 0 And IsNumeric(v1) And Val(v1) = 0 Then
      If ws.Cells(lRow, "B").Value <> "GBP" Then
         If ws.Cells(lRow, "B").Value <> "EUR" And ws.Cells(lRow, "A").Value <> "AL1234" Then
            ws.Rows(lRow).Delete Shift:=xlUp 
         End If
      End If
   End If 
Next lRow

I'm not sure if you still needed your original test so I left it in.
[/code]
 
Upvote 0
I haven't tested this, but I think it should work:

Code:
Sub test()
Dim LastRow As Long, i As Long

With Sheets("EQUITY REPORT")
    LastRow = .Range("B65536").End(xlUp).Row

    For i = LastRow To 1 Step -1
        Select Case .Cells(i, "B").Value
            Case Is = "EUR"
                If .Cells(i, "A") <> "AL1234" Then
                    .Rows(i).Delete
                End If
            Case Is <> "GBP"
                .Rows(i).Delete
        End Select
    Next i
End With
                
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,692
Members
448,979
Latest member
DET4492

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