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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,222,384
Messages
6,165,669
Members
451,983
Latest member
Raph24

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