+ Reply to Thread
Results 1 to 5 of 5

"Object required" error with VBA loop rows deleting

Hybrid View

  1. #1
    Registered User
    Join Date
    07-22-2012
    Location
    POLAND
    MS-Off Ver
    Excel 2003
    Posts
    2

    "Object required" error with VBA loop rows deleting

    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
    Last edited by Cutter; 07-22-2012 at 08:50 AM. Reason: Added code tags

  2. #2
    Forum Contributor
    Join Date
    07-04-2012
    Location
    Al Khor, Qatar
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: "Object required" error with VBA loop rows deleting

    @ts I suggest you attached the file so that the macro can easily be changed within the excel file you are using.

  3. #3
    Registered User
    Join Date
    07-22-2012
    Location
    POLAND
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: "Object required" error with VBA loop rows deleting

    That's the file.
    Attached Files Attached Files

  4. #4
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: "Object required" error with VBA loop rows deleting

    Hello JKWIN, and welcome to the forum.

    Please notice that code tags have been added to your post(s). The forum rules (Rule #3) require them so please keep that in mind and add them yourself whenever showing code in any of your future posts.
    Thanks.

    RULE 3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

  5. #5
    Forum Contributor
    Join Date
    07-04-2012
    Location
    Al Khor, Qatar
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: "Object required" error with VBA loop rows deleting

    hi kindly check this macro.. please inform me if this helps.
    'Excel 2007
    Sub planp()
    
    Dim n
    Dim eCell
    Dim eCell1
    Dim eCell2
    
    For n = 10 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 'if a cell contains "1"
    
    Do While eCell.Offset(1, 0).Value = ""
    Worksheets("Arkusz4").Rows(n + 1).Delete 'removing row below that containing "1"
    
    
    Loop
    Worksheets("Arkusz4").Rows(n).Delete 'removing row containing "1"
    End If
    Next
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1