+ Reply to Thread
Results 1 to 7 of 7

Error Message with For Loop

  1. #1
    Registered User
    Join Date
    03-21-2010
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    90

    Error Message with For Loop

    Hi,

    I am trying to create a loop that deletes rows within my worksheet. However, the data in the spreadsheet will change every month so I can't add definite ranges in my code. The code below works but when it finished I get a runtime error '10004' message. Please help me here.

    Thanks!

    HTML Code: 
    Last edited by jadown; 07-17-2013 at 08:15 AM.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Error Message with For Loop

    The code is looping 200 times. Why can not you select a range and delete?

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Error Message with For Loop

    Hi, jadown,

    you have to make sure that the last line of data is longer than 202 rows - with less you would go over the limits of Rows.Count when you try to delete rows. You should search for a constant and delete from there on. Your code may be further simplified to

    Please Login or Register  to view this content.
    Maybe you could post a workbook with some sample data to adjust the macro.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Registered User
    Join Date
    03-21-2010
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    90

    Re: Error Message with For Loop

    ExcelForumEx.xls

    Here is the file a much smaller file. But the rows highlighted in yellow is what I want the loop to delete.

    Thanks!

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Error Message with For Loop

    Hi, jadown,

    I altered the requirement to delete the single entry in Column C which would have been left as well:

    Please Login or Register  to view this content.
    Ciao,
    Holger

  6. #6
    Registered User
    Join Date
    03-21-2010
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    90

    Re: Error Message with For Loop

    Holger,

    Thank you so much because I couldn't figure out how to get past this error all day.

    Thanks Again!

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Error Message with For Loop

    Hi, jadown,

    you´re welcome - thanks for the feedback. If the solution fits your needs please mark this thread as Solved:
    To mark your thread solved do the following:
    - Go to the first post
    - Click edit
    - Click Advance
    - Just below the word "Title:" you will see a dropdown with the word No prefix.
    - Change to Solve
    - Click Save
    Ciao,
    Holger

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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