+ Reply to Thread
Results 1 to 5 of 5

Execute Code based on a set of items contained in an array

  1. #1
    Forum Contributor
    Join Date
    05-02-2012
    Location
    Mosselbaai, Suid Afrika
    MS-Off Ver
    Excel 2016
    Posts
    107

    Execute Code based on a set of items contained in an array

    If it is possible I would like to have code that executes different macros based on the content of a set of values, or the content of an array.

    I populate an array with True and False values, based on a set of selections.
    Depending on the selected options the array will contain any of the following sets:
    Set1 = {"True", "False", "True", "False", "True", "False"}
    Set2 = {"True", "False", "True", "False", "False", "True"}
    Set3 = {"True", "False", "False", "True", "True", "False"}
    Set4 = {"True", "False", "False", "True", "False", "True"}
    Set5 = {"False", "True", "False", "False", "True", "False"}
    Set6 = {"False", "True", "False", "False", "False", "True"}

    What I would like to do then is to use the Case statement something like this:

    Select Case Set
    Case 1
    program statements
    Case 2
    program statements
    Case 3
    program statements
    Case 4
    program statements
    Case 5
    program statements
    Case 6
    program statements
    End Select

    I hope this is at all possible. Thanks.

  2. #2
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Execute Code based on a set of items contained in an array

    If statements are generally faster than select statements, and in this case it would seem to me doubly so.

    So why not something like the following?

    Please Login or Register  to view this content.
    I didn't test this code, so there might be some mistake in it. But the idea should be correct.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,545

    Re: Execute Code based on a set of items contained in an array

    One way
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    05-02-2012
    Location
    Mosselbaai, Suid Afrika
    MS-Off Ver
    Excel 2016
    Posts
    107

    Re: Execute Code based on a set of items contained in an array

    Thanks a million, it works like a charm!

  5. #5
    Forum Contributor
    Join Date
    05-02-2012
    Location
    Mosselbaai, Suid Afrika
    MS-Off Ver
    Excel 2016
    Posts
    107

    Re: Execute Code based on a set of items contained in an array

    Thanks Jindon, I will try this out as well. I don't fully understand what the code does but will try and figure it out.

+ 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