+ Reply to Thread
Results 1 to 7 of 7

Running or bypassing code in a macro based on a certain condition...

  1. #1
    Registered User
    Join Date
    01-11-2010
    Location
    tracy, ca
    MS-Off Ver
    Excel 2003
    Posts
    39

    Running or bypassing code in a macro based on a certain condition...

    I want to be able to run a certain chunk of code in the macro if a certain condition is true, or if that condition is not true then I want to bypass that chunk of code. It doesn't matter if this is accomplished with an if... then... else statement, or some other way. I'm just looking for a general method for accomplishing this. Thank you!
    Last edited by kenab1; 02-17-2010 at 03:55 PM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Running or bypassing code in a macro based on a certain condition...

    Your question is too vague to be able to provide a specific answer. But If/Then/Else sounds very sensible. If you want more tailored advice, post specific details and a workbook.

  3. #3
    Registered User
    Join Date
    01-11-2010
    Location
    tracy, ca
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: Running or bypassing code in a macro based on a certain condition...

    Ok here's the code:

    Please Login or Register  to view this content.
    The first and second parts will always be run no matter what. I only want the third part to run if myNum is 3 or greater, otherwise I want the macro to skip it entirely. Thanks!

  4. #4
    Registered User
    Join Date
    01-11-2010
    Location
    tracy, ca
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: Running or bypassing code in a macro based on a certain condition...

    Actually I figured it out. Thanks though!

  5. #5
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Running or bypassing code in a macro based on a certain condition...

    I don't know but instructions are at the top of the page. Perhaps you could post your solution for the benefit of others.

  6. #6
    Registered User
    Join Date
    01-11-2010
    Location
    tracy, ca
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: Running or bypassing code in a macro based on a certain condition...

    I just added two If statements within the third section of the code, did the job nicely. Completely negates that section from running at all.

    Please Login or Register  to view this content.

  7. #7
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Running or bypassing code in a macro based on a certain condition...

    Good work. Thanks.

+ 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