delete row if row,Col C value is "L" and next column value is zero

banana99

New Member
Joined
Mar 13, 2013
Messages
35
Hi, I can't seem to figure this one out. I think I'm close, but it just seems to keep deleting each row and will not exit the loop if the first condition is false. Thanks!
Code:
     With ActiveSheet
                .Select
                ViewMode = ActiveWindow.View
                ActiveWindow.View = xlNormalView
                .DisplayPageBreaks = False
                Firstrow = .UsedRange.Cells(1).Row
                Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
                For Lrow = Lastrow To Firstrow Step -1
                    With .Cells(Lrow, "C")
                        If Not IsError(.Value) Then
                        
                            If .Value = "L" & ActiveCell.Offset(0, 1).Select = 0 Then .EntireRow.Delete
                        Else: End If
                    End With
                Next Lrow
            End With
 

Some videos you may like

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

sky1in5

Active Member
Joined
Dec 24, 2012
Messages
396
Code:
Sub test()
Dim LastRow, i As Long
LastRow = ActiveSheet.Range("C" & Rows.Count).End(xlUp).Row
For i = 1 To LastRow
If ActiveSheet.Range("C" & i).Value = "l" Then

If ActiveSheet.Range("D" & i).Value = "0" Then

Rows(i).Delete
i = i - 1
i = i + 1
i = i - 1

End If

End If
Next
End Sub
 

banana99

New Member
Joined
Mar 13, 2013
Messages
35
Thanks sky, I think this almost does it, but I need to look for a string "L" for column C and looking for Column D same row with value of zero, if then and only then delete that row. Column C must contain "L" first, then if D same row is zero then delete.
 

mirabeau

Banned user
Joined
Nov 4, 2010
Messages
2,075
Code:
Sub xnx()
Dim i, s
s = Chr(30)
For i = Cells.SpecialCells(11).Row To 1 Step -1
    If Cells(i, "C") & s & Cells(i, "D") = "L" & s & 0 Then Rows(i).Delete
Next
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,521
Messages
5,596,648
Members
414,083
Latest member
Mrsash

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
Top