+ Reply to Thread
Results 1 to 6 of 6

Improving my Error Handling With Arrays

  1. #1
    Registered User
    Join Date
    06-22-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    10

    Improving my Error Handling With Arrays

    Alright. I've got a general function that takes a pattern as a string and an (optional) name of a workbook. It then looks through all of the sheets in that workbook, and creates an array of the sheets that match that pattern. Basically, it's a sheet searching function. What I'm proud of is its flexibility. What I'm not proud of is its error handling abilities. If something goes wrong, it goes straight to code/compiler errors. If it can't find any sheets, invalid strings, workbook isn't there, etc.

    So. I need help improving it's ability to respond to bad situations in a more productive way than spitting errors at me.

    Please Login or Register  to view this content.
    What do you think? How can I make this code better?

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,376

    Re: Improving my Error Handling With Arrays

    maybe so
    Please Login or Register  to view this content.
    see also here

  3. #3
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Improving my Error Handling With Arrays

    I'd change it to take a workbook object as the second argument and I'd convert the sheet names and pattern to lower case before using Like so that the match is case insensitive.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  4. #4
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Improving my Error Handling With Arrays

    I prefer handling objects to strings, and avoid dynamic redimensioning of arrays:

    Please Login or Register  to view this content.
    EDIT:
    and avoid dynamic redimensioning of arrays
    And notice that nilem does as well
    Last edited by shg; 07-23-2012 at 02:53 PM.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    06-22-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Improving my Error Handling With Arrays

    Thanks to all of you. I'll be improving the code shortly.
    A question for nilem, or anyone else who knows what this does.

    "On Error Resume Next: Err.Clear"

    I see this On Error Resume Next thing everywhere, and I can't really understand the explanations in the reference library. Both what it does, and why it's so common.

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Improving my Error Handling With Arrays

    on error resume next suppresses any runtime errors that may occur and simply carries on processing the next line of code. it is often overused but has its place as long as it is limited in scope.

+ 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