+ Reply to Thread
Results 1 to 2 of 2

Range.Delete causing object error 424

  1. #1
    Forum Contributor banaanas's Avatar
    Join Date
    08-26-2014
    Location
    Finland
    MS-Off Ver
    2016
    Posts
    199

    Range.Delete causing object error 424

    Hi!

    I am trying to create a macro that checks all cells in range for a match, and if found will delete a part of the range.
    Everything works fine until my code deletes the first cells of the range, then on the next loop, it crashes with runtime error 424 objecr required.

    This has to have something to do with the original range changing right? Is there a way how to continue my loop?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,640

    Re: Range.Delete causing object error 424

    Hi,

    Indeed, main problem is that after first delete, the cell assigned to FoundOne range variable is deleted (it was first cell found with Find, so it's first meeting criteria in
    Please Login or Register  to view this content.
    loop)
    so next call to:
    Please Login or Register  to view this content.
    generates an error. because VBA cannot evaluate FoundOne.value (as FoundOne has been already deleted)

    One possibility is to assign "just found" FoundOne.value to a variable, and then compare cell.value with that variable. Or (shall be quicker) just repeat Find, not look for each cell to compare with Find result, like :

    Please Login or Register  to view this content.
    PS. It's not necessary, but makes reading easier if you declare all variables. for instance in the code
    Please Login or Register  to view this content.
    declarations would make reading easier, and (may be it is declared somewhere public, because otherwise would cause an error , lastrow has no assigned value
    Best Regards,

    Kaper

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Any guess on why this macro is causing a subscript out of range error?
    By 80Wil in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-21-2017, 07:07 PM
  2. Method 'Delete' of object 'Range' failed - Error
    By JimmyA in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-24-2017, 01:20 PM
  3. Range formula is causing me error 1004.
    By redsab in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-21-2016, 01:12 PM
  4. [SOLVED] object invoked error causing excel to crash
    By edopts in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-11-2014, 12:55 PM
  5. [SOLVED] Set Range syntax - currently causing #value! error sometimes
    By kamelkid2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-17-2014, 03:11 PM
  6. [SOLVED] Selecting range causing error
    By kosherboy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-30-2014, 02:24 PM
  7. -2 for shapetype causing subscript out of range error.
    By leaning in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-20-2011, 05:31 PM

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