+ Reply to Thread
Results 1 to 3 of 3

How to run X number of for loops

  1. #1
    Registered User
    Join Date
    04-15-2014
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2013
    Posts
    1

    How to run X number of for loops

    Hello, I'm trying to run a variable number of for loops. For example -

    Please Login or Register  to view this content.
    where the number of loops (i, j, k... in this case, 3) is variable.

    More broadly, I'm trying to find out different combinations of sporting events and loop through assigned probabilities to see the probability of an outcome (i.e. home team wins i, away team wins j, home team wins k, etc...), and I don't know in advance how many sports games there will be (and there could be many).

    Thanks for the help!

  2. #2
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: How to run X number of for loops

    Use multi dimensional arrays with an incremented variable to access the second dimension, http://www.homeandlearn.org/multidim...al_arrays.html

  3. #3
    Valued Forum Contributor Maudibe's Avatar
    Join Date
    12-21-2016
    Location
    USA
    MS-Off Ver
    2010-2013
    Posts
    326

    Re: How to run X number of for loops

    Many different ways to do this. I will describe a few here:

    If a sport has a named range for the probabilities called "Sport1_prob" in cells A1 to A5, you can cycle through that range with something like:
    Please Login or Register  to view this content.
    You can use the range directly if there is no named range
    Please Login or Register  to view this content.
    Alternately, in the same scenario above you can perform looping using the For...Each method
    Please Login or Register  to view this content.
    If you want to cycle through the probabilities in a list from A1 to A5 and the list may eventually expand unlimited down column A, you can use this method:
    Please Login or Register  to view this content.
    Note that the 1 (highlighted in red) indicates it is looking down column 1

    Use any of the loop methods embedded within each other as you described in the post.

    HTH,
    Maud

+ 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. Can I use the Range("65536").Endx1Up As a number in Loops
    By LewisLonsdale in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-25-2015, 11:16 AM
  2. [SOLVED] Code that loops through number of files and runs a called sub on each works sometimes. Why
    By jbwitty in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-01-2013, 05:34 PM
  3. Indefinite number of loops
    By catalinand in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-14-2012, 09:57 AM
  4. [SOLVED] How do I write a vba code which counts a number of loops?
    By helium in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-25-2012, 07:01 PM
  5. [SOLVED] Getting index number when using For Each... loops
    By Jacc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-10-2012, 05:23 PM
  6. Loops
    By David in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-10-2006, 07:00 PM

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