+ Reply to Thread
Results 1 to 2 of 2

Pausing code on Error then resuming once resolved

  1. #1
    Registered User
    Join Date
    09-26-2007
    Posts
    1

    Pausing code on Error then resuming once resolved

    G'day people,
    I was hoping that I would be able to gain some guidance on the following issue I have been attempting to resolve,

    Currently I am working on an excel document that incorporates multiple functions and sub procedures, it involves taking an array of data, applying data verifcation tests then once passed applying the necessary modifications to the data as set by the user, it follows the proceding basic framework

    sub mysub()

    dim testbool as boolean

    'The Data is sourced from a defined range, say 'Data'

    testbool = Data_Verify(Data)

    if testbool = true then
    'go ahead with modifications
    else
    'abort and re-enter data
    end if
    end sub

    Unfortunately there is alot of data verification tests that need to be performed, which may only be a slight modification, ie non-empty field etc. At this point the function Data_Verify(Data) has the following framework

    function Data_Verify(Data)

    'perform test 1
    if 'test1 fail' then
    Data_verify = false
    exit function
    end if
    'perform test 2
    " "
    " "
    and so on
    end function

    Obviously as it performs each test if it finds a failed test the function is exited and then the sub. I was hoping that it may be possible to pause the running of the code on an error, allow the user to make a modification and then resume the code.
    ie
    function Data_Verify(Data)

    On Error GoTo Errorcheck

    'perform test one
    if test is failed then
    Error 5000 ' create my own error value
    end if

    'perform test 2
    if test is failed then
    Error 5001 ' create another error value
    end if

    'and so on

    'create error check
    Errorcheck :
    select case err.number

    case err.number = 5000
    'here is where I was hoping I would be able to enter some code to
    stop running the program(or should I say pause the program), alert the user what needs to be changed via a msgbox and allow the user to change the value in the spreadsheet then possibly hit a commandbutton I keep invisible until the error occurs to signify that a change has occured and then resume the code at the next line.

    resume next

    case err.number = 5001
    'and so on

    end select

    I apologise if I havent worded (and or structured) the question in the appropriate manner, unfortunately I do not possess any formal training in excel vba.

    Any help would be greatly appreciated,

    David

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    dp_galea

    Welcome to excelforum

    Please read forum rules & wrap your VBA code
    See links below for rules

    If you do not understand the VBA code wrap instructions have a look at my last reply in this thread
    http://www.excelforum.com/showthread.php?t=583950
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

+ 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