+ Reply to Thread
Results 1 to 3 of 3

Simple Error Handling

  1. #1
    Forum Contributor
    Join Date
    09-13-2011
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    111

    Simple Error Handling

    Hi,

    I have a simple questions. I'm pretty new to VBA and want to include good error handling techniques in my code. Currently, I'm trying to write a simple module that will have an input box to allow a user to enter in a number, and then print/insert that number into a cell. But, there are two issues with my code. Please see below:

    Please Login or Register  to view this content.
    First, as you can see, if a person places an integer inside of the input box; then a mismatch error will occur. I was trying to map the error, or handle the error, by using a the
    Please Login or Register  to view this content.
    line. Before that, I was trying

    Please Login or Register  to view this content.
    then the code will resume.

    Second problem, there's a vbcancel button in the input box. If I press "cancel", I get an error message. I tried the following:

    Please Login or Register  to view this content.
    I think it's the same problem above, but I don't know. Any help would be appreciated.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Simple Error Handling

    Declare n as Variant instead of Integer.

    Oh, and you don't need On Error Goto.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    09-13-2011
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    111

    Re: Simple Error Handling

    Your awesome, this also handled the "vbCancel" issue. Thanks. FYI,

    Please Login or Register  to view this content.

+ 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