+ Reply to Thread
Results 1 to 4 of 4

'Goto' when a Value is no Longer Met

  1. #1
    Registered User
    Join Date
    12-17-2014
    Location
    Perth, Australia
    MS-Off Ver
    Windows 7
    Posts
    85

    'Goto' when a Value is no Longer Met

    Hi, I have a string called errorMessage. If my VBA program incounters an error or a bad user input, the errorMessage string changes from blank to the error that is present. Throughout my program, I am constantly checking to see if the errorMessage string is still blank, see below:

    Call resetWorkbookAndVerify
    If errorMessage <> "" Then GoTo couldNotExecute

    Call verifyUserIput
    If errorMessage <> "" Then GoTo couldNotExecute

    Call importData_FullList
    If errorMessage <> "" Then GoTo couldNotExecute

    Is there a way to immediately 'GoTo' when my string is not blank, or do I need to keep checking the errorMessage. I'm hope for something like the 'On Error GoTo' function, which will immediately 'GoTo' on any error, but rather 'GoTo' on any string value.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: 'Goto' when a Value is no Longer Met

    One way to pass an error back to a calling routine is to cast the sub as a function.

    Please Login or Register  to view this content.
    Then the calling routine can use

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    12-17-2014
    Location
    Perth, Australia
    MS-Off Ver
    Windows 7
    Posts
    85

    Re: 'Goto' when a Value is no Longer Met

    Thanks Mike, but my errorMessage isn't usually a system error, rather a 'if cells(1,1) = "" then errorMessage = "Please enter a value in the cell"'. So unless I force a system error after setting the errorMessage, I'm not sure this will work?

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,570

    Re: 'Goto' when a Value is no Longer Met

    Please Login or Register  to view this content.
    Ben Van Johnson

+ 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] GOTO sucks, but can I "GOTO Variable"?
    By smpita in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 06-25-2014, 03:14 PM
  2. Goto First New Post No Longer Working
    By JBeaucaire in forum Suggestions for Improvement
    Replies: 9
    Last Post: 05-01-2012, 10:07 AM
  3. Using a VAR with a Goto
    By stephaneg in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-12-2010, 06:52 AM
  4. Something like Goto
    By StarShaper in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-30-2007, 06:11 PM
  5. When To use GOTO Sub?
    By MC82 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-09-2006, 10:10 PM
  6. If.....Then GoTo.......
    By Alec H in forum Excel General
    Replies: 4
    Last Post: 02-22-2006, 10:42 AM
  7. How to goto in VBA
    By Gazzer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-15-2005, 04:59 AM

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