Object required error with VBA rows deleting

jkwin

New Member
Joined
Jul 22, 2012
Messages
2
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.
Someone helps?

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
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Welcome to the forum!

Try this,
Code:
[FONT="Consolas"][SIZE="2"][COLOR="Navy"]Sub planp()

    Dim n

    With Worksheets("Arkusz4")
        For n = 64 To 1 Step -1
            If Right(.Cells(n, 1), 1) = "1" Then
                Do While .Cells(n + 1, "A") = "" And .Cells(n + 1, "K") <> ""
                    .Rows(n + 1).Delete
                Loop
                .Rows(n).Delete
            End If
        Next
    End With

End Sub
[/COLOR][/SIZE][/FONT]
 
Upvote 0

Forum statistics

Threads
1,215,373
Messages
6,124,545
Members
449,169
Latest member
mm424

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