jkwin
07-22-2012, 04:22 AM
The macro below should remove rows with text in column "A" containing "1" digit(e.g. A1, AB1) and rows below it, if cell in column "A" is empty and cell in column "K" is not empty. When there is a row with "1" and one row below it- macro removes this row below, then the error appears: "Object required" and a row with "1" is not removed. When there are only rows with "1" without these rows below - it is ok, the rows are removed.
Sub planp()
Dim n
Dim eCell
Dim eCell1
Dim eCell2
For n = 64 To 1 Step -1
Set eCell = Worksheets("Arkusz4").Cells(n, 1)
Set eCell1 = Worksheets("Arkusz4").Cells(n + 1, 1)
Set eCell2 = Worksheets("Arkusz4").Cells(n + 1, 11)
If Right(eCell.Value, 1) = "1" Then
Do While eCell1.Value = "" And eCell2.Value <> ""
Worksheets("Arkusz4").Rows(n + 1).Delete
Loop
Worksheets("Arkusz4").Rows(n).Delete
End If
Next
End Sub
Sub planp()
Dim n
Dim eCell
Dim eCell1
Dim eCell2
For n = 64 To 1 Step -1
Set eCell = Worksheets("Arkusz4").Cells(n, 1)
Set eCell1 = Worksheets("Arkusz4").Cells(n + 1, 1)
Set eCell2 = Worksheets("Arkusz4").Cells(n + 1, 11)
If Right(eCell.Value, 1) = "1" Then
Do While eCell1.Value = "" And eCell2.Value <> ""
Worksheets("Arkusz4").Rows(n + 1).Delete
Loop
Worksheets("Arkusz4").Rows(n).Delete
End If
Next
End Sub