+ Reply to Thread
Results 1 to 9 of 9

Macro that skips to another macro if no numbers are found

  1. #1
    Registered User
    Join Date
    07-20-2015
    Location
    New York
    MS-Off Ver
    2305 - Enterprise 365
    Posts
    147

    Macro that skips to another macro if no numbers are found

    Hello All,
    I need a macro that skips to certain macro (e.g. "Macro_X") if the macro cannot find any numbers separated by a blank space either before or after said numbers in a range (B4:B). If the macro does, in fact, find numbers separated by a blank space before or after them along with any text, then the macro simply ends.
    I have attached an example with two worksheets showing the two different scenarios. In the first worksheet (without separated numbers), the macro would skip to "Macro_X" and in the second worksheet (with separated numbers), the macro would end.

    Best,
    Andrewstupendo
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    10-08-2018
    Location
    Lima, Peru
    MS-Off Ver
    Office 365 ProPlus
    Posts
    148

    Re: Macro that skips to another macro if no numbers are found

    This macro will do. Need to insert it in a module:

    Please Login or Register  to view this content.
    Leo Skywalker
    May the force be with you.

  3. #3
    Registered User
    Join Date
    07-20-2015
    Location
    New York
    MS-Off Ver
    2305 - Enterprise 365
    Posts
    147

    Re: Macro that skips to another macro if no numbers are found

    Hello Leoskywalker,
    The macro worked quite nicely if no separate numbers were found in the spreadsheet.
    However, I received the attached error message if numbers were, in fact, present.

    Also, I realized that the macro that needs to be "skipped to" is part of the larger chained-together macro.
    Therefore, the "sub-macro" (i.e. Macro X) within the context of the larger macro needs to be referred to
    in order to avoid shutting down the larger macro.
    So in other words, code is needed so that if no numbers are found and one skips to "Macro_X",
    the larger macro still needs to function. I apologize if I did not explain this earlier.
    e.g.
    Please Login or Register  to view this content.
    Best,
    Andrewstupendo
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by Andrewstupendo; 11-06-2018 at 04:34 PM.

  4. #4
    Forum Contributor
    Join Date
    10-08-2018
    Location
    Lima, Peru
    MS-Off Ver
    Office 365 ProPlus
    Posts
    148

    Re: Macro that skips to another macro if no numbers are found

    You ghave inserted the code in a WORKSHEET, you need to insert the code in a MODULE, please see the file attached.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    07-20-2015
    Location
    New York
    MS-Off Ver
    2305 - Enterprise 365
    Posts
    147

    Re: Macro that skips to another macro if no numbers are found

    Thanks for that.

  6. #6
    Forum Contributor
    Join Date
    10-08-2018
    Location
    Lima, Peru
    MS-Off Ver
    Office 365 ProPlus
    Posts
    148

    Re: Macro that skips to another macro if no numbers are found

    You're welcome, you can mark the post as solved.


  7. #7
    Registered User
    Join Date
    07-20-2015
    Location
    New York
    MS-Off Ver
    2305 - Enterprise 365
    Posts
    147

    Re: Macro that skips to another macro if no numbers are found

    Hello LukeSkywalker,
    There is another aspect to this problem that I want to address.
    Namely, that the macro which you created is now part of a larger macro.
    So, my question: if there are no numbers found using your macro, FindNumbers,
    is it possible to end the larger macro that it is a part of and then call another macro like myDummyMacro which is NOT part of
    Larger_Macro?
    here is the code for the Larger macro.
    Please Login or Register  to view this content.
    Your code for FindNumbers would be designed so that the Larger_Macro would end in the
    middle of its run if no numbers were found and then FindNumbers would call on myDummyMacro.
    So your code would look something like this I suppose:
    Please Login or Register  to view this content.
    I apologize for this oversight and that I did not think of this before.
    Best,
    Andrewstupendo

  8. #8
    Forum Contributor
    Join Date
    10-08-2018
    Location
    Lima, Peru
    MS-Off Ver
    Office 365 ProPlus
    Posts
    148

    Re: Macro that skips to another macro if no numbers are found

    It's not possible to do it the way you want it, because when you call another sub, no matter where ig goes, or what it does; it will always return with the next line.
    if you want to transfer the control to control to another sub, then it has to be the last line, see the example:

    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    07-20-2015
    Location
    New York
    MS-Off Ver
    2305 - Enterprise 365
    Posts
    147

    Re: Macro that skips to another macro if no numbers are found

    Thank you once again LeoSkywalker, for the solution to my second problem. Great job! Andrewstupendo. P.S. I would add another star to your reputation, but the website does not allow.,

+ 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] macro showing error ( macro not found ) while trying to execute macro every 1 minute
    By prabhuduraraj09 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2018, 07:58 PM
  2. [SOLVED] Macro that rounds but skips cells if blank
    By Hood in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-19-2016, 07:28 PM
  3. [SOLVED] Macro to update skips
    By ricklou in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-24-2016, 01:59 PM
  4. Macro that calculates average of a column and skips 0 or #VALUE!
    By Tmc2159 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-18-2013, 01:56 PM
  5. [SOLVED] Macro skips generating last email
    By csit17 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-17-2012, 07:48 AM
  6. Macro finds matching values but skips code after?
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-22-2011, 08:32 AM
  7. Macro that skips cells of a certain specification
    By Guest001 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-19-2008, 05:41 AM

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