+ Reply to Thread
Results 1 to 9 of 9

How Do I stop this macro from running if there is an error?

  1. #1
    Registered User
    Join Date
    02-17-2011
    Location
    NC
    MS-Off Ver
    Excel 2003
    Posts
    8

    Question How Do I stop this macro from running if there is an error?

    The function below works if it finds 'NAME'. However, if 'NAME' is not found I get an error message and I haven't been able to figure out how to stop the function if there is an error.

    Thank you
    John

    Please Login or Register  to view this content.
    Last edited by jwichern1; 03-03-2011 at 04:41 PM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: How Do I stop this macro from running if there is an error?

    Assign the result of the search to a range variable and test if there is anything there:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-17-2011
    Location
    NC
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: How Do I stop this macro from running if there is an error?

    Thank you for your quick response. However I am getting a Run-Time error '13': Type Mismatch. Any suggestions how to correct this?

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: How Do I stop this macro from running if there is an error?

    On which line? Does this work?
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-17-2011
    Location
    NC
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: How Do I stop this macro from running if there is an error?

    It kind-of works, but when the code is run it deletes the row where the 'NAME' was defined, which is a different sheet. I would like it to delete the row on the data sheet where it found the match.

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: How Do I stop this macro from running if there is an error?

    I would have thought it should do that. This is where you attach a workbook.

  7. #7
    Registered User
    Join Date
    02-17-2011
    Location
    NC
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: How Do I stop this macro from running if there is an error?

    I added the code below after defining 'NAME' and that seems to have corrected:

    Please Login or Register  to view this content.
    So full code reads:
    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: How Do I stop this macro from running if there is an error?

    Rows(r.Row).Delete Shift:=xlUp

    Your problem was stemming from this line. You were seaching for the row and your data sheet but THEN the line above was telling it to remove the Row on the currenlty active sheet.

    Here's this line corrected so that it removes from the data sheet ... even if the data sheet is not the active sheet.

    Please Login or Register  to view this content.

  9. #9
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: How Do I stop this macro from running if there is an error?

    Sorry, wasn't paying attention. Either a sheet reference or nimrod's approach will sort it out.

+ 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