+ Reply to Thread
Results 1 to 19 of 19

Add Code To Ignore Errors

  1. #1
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Add Code To Ignore Errors

    Hello,

    My workbook contains a sheet with code which works very well, unless there is an unexpected entry. Then I get a run-time error '13' type mismatch. I'm wondering if there is a simple way to insert a few lines of code that if an error occurs, it is just ignored and nothing happens. Is there something that simple?

    This is the code for the sheet in question:

    Please Login or Register  to view this content.
    There is so much good in the worst of us,
    And so much bad in the best of us,
    That it hardly behooves any of us
    To talk about the rest of us.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,841

    Re: Add Code To Ignore Errors

    Where is the unexpected entry, and what line of code causes the error?

    A generic answer is to insert the following line of code at the top of the Sub:

    Please Login or Register  to view this content.
    but this could backfire on you, and I normally don't advise it. It would be better to analyze where errors could occur and isolate those spots. Otherwise you could be ignoring errors other than the ones you want to ignore, wreaking havoc.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Add Code To Ignore Errors

    This part here seems to hang when a number is incorrectly entered, for example a 2.0. instead of 2.0:

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Add Code To Ignore Errors

    Hello swordswinger710,

    Your code could also require to disable Events, to add to what 6StringJazzer commented. Maybe we should take it step by step, and first tell us at which line of your code do the Error Message appear?

    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  5. #5
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Add Code To Ignore Errors

    Thank you Winon, I think you missed my last post there. Does that help to narrow it down?

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Add Code To Ignore Errors

    Hi swordswinger710,

    This is almost like extracting a bad tooth with a chisel and hammer!

    Can you perhaps provide us with a sample Workbook, with all your Code, as it seems that you may have some UDF's in there somewhere as well?

    Regards.
    Last edited by Winon; 09-07-2016 at 03:34 PM. Reason: LOL I spelled as with a double s, making an as* of myself!

  7. #7
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Add Code To Ignore Errors

    Alright, point taken. Take a look at this attachment. I ran into the problem when a value in X or Z doesn't contain a number it can work with, such as '2.0.' for example. See what you think.
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Add Code To Ignore Errors

    Now what do you want? Do you want to throw any error message when the cell does not contain any number, or you want to convert that entry to a number?

  9. #9
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Add Code To Ignore Errors

    If you want to throw a message then use this:
    Please Login or Register  to view this content.
    If you want to convert that to a valid number then use this: Val(Rx) and Val(Rz) Instead of Rx and Rz in formulas and conditions.

  10. #10
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Add Code To Ignore Errors

    Hi swordswinger710,

    With some Excel Formulas, Data Validations, Hidden Helper Columns, and Copy and Paste restrictions, please have your file back. Hope you have access to a Shredding Machine 'cause I don't posses such luxury.

    Kind Regards.
    Attached Files Attached Files

  11. #11
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Add Code To Ignore Errors

    Thanks for all your help guys, I really appreciate it.

    What I think might serve me best is to come up with a way to skip the code if the right format is not present like I'm already doing here:

    Please Login or Register  to view this content.
    What would be the cleanest way of specifying that if either the X or the Z column do not contain something like '#.#' then the rest of the macro can be skipped as well?

  12. #12
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Add Code To Ignore Errors

    I've been trying to use something like this to keep things as clean as possible:

    Please Login or Register  to view this content.
    ...but I must not be adding it to my existing code properly, as the code only runs for the first entry in X or Z and then doesn't anymore. How can I fix this?
    Attached Files Attached Files

  13. #13
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Add Code To Ignore Errors

    This is happening because you didn't add this line at the end of code :
    Please Login or Register  to view this content.
    You have declared
    Please Login or Register  to view this content.
    at the top which is stopping all events for future. Then you have used
    Please Login or Register  to view this content.
    in the IF condition which is enabling the events before exiting the sub if the IF condition is true. So you need to add this line again at the end of code.

  14. #14
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Add Code To Ignore Errors

    Is this correct? It doesn't seem to be working either:

    Please Login or Register  to view this content.

  15. #15
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Add Code To Ignore Errors

    This should work. May be the events are still disabled in your file. You can close the file and reopen it to enable the events again. Also I have attached the working file here. See this.
    Attached Files Attached Files

  16. #16
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Add Code To Ignore Errors

    Oh I get it now, thank you! This almost works, but it also considers '2.0' an invalid entry as well. Is there a simple way to allow periods followed by a zero?

  17. #17
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Add Code To Ignore Errors

    I made little correction there. Hope that it will work now.
    Please Login or Register  to view this content.

  18. #18
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Add Code To Ignore Errors

    That, my friend, does it. Thank you so much!

  19. #19
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Add Code To Ignore Errors

    You are most welcome.

+ 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. [SOLVED] How to ignore errors in a sum
    By Jaspal in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-09-2013, 04:37 AM
  2. [SOLVED] re: how to ignore !num errors in graph
    By 4GONERS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-03-2013, 04:11 PM
  3. [SOLVED] How to do sum-up and ignore errors?
    By BNCOXUK in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-26-2013, 07:03 AM
  4. Ignore Errors in SUM
    By w424637 in forum Excel General
    Replies: 3
    Last Post: 02-13-2007, 02:42 AM
  5. [SOLVED] vlookup, but ignore errors if #n/a
    By Jess in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 04:05 PM
  6. vlookup, but ignore errors if #n/a
    By Jess in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 PM
  7. vlookup, but ignore errors if #n/a
    By Jess in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 11:05 AM
  8. vlookup, but ignore errors if #n/a
    By Jess in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 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