+ Reply to Thread
Results 1 to 3 of 3

selecting a random value in an array under a condition

  1. #1
    Registered User
    Join Date
    03-01-2019
    Location
    Mansfield
    MS-Off Ver
    2013
    Posts
    19

    selecting a random value in an array under a condition

    Hi,
    i'm currently writing some code in which I simulate the population dynamics of a butterfly and its host plant. I now have two arrays for the within season dynamics of the plant and insect.

    within the first array i show plant IDs, their current patch (random between 1 to 5) as well as the current day within a season (each plant and butterfly is iterated through 120 days), flowering day for the plant and the number of eggs laid on the plant.

    in the butterfly array i also show butterfly ID, day, emergence day from pupae, the plant the butterfly is currently found in and the patch the host plant is found in.

    now, i wrote some code in which i state that if the current day is equal to the day of butterfly emergence, the butterfly lays 26 eggs. those 26 eggs need to be laid on a RANDOM plant (ech butterfly lays one egg per plant) within the patch the butterfly is currently found. The total number of eggs per plant is to be recorded on the plant array. I'm not sure how to do that. Bare in mind i will also need to iterate the array for the number of seasons in question as currently the values show only the behaviour of plants and butterflies in a period of 120 days i.e. one season (which by the way is also something i have a problem with but on that perhaps in a later thread). I would attach my file but not sure why i'm not able to and pasting the code onto the thread seems a little silly considering i have about 450 lines of code so I apologise if this isn's very clear from my explanation.

    any suggestions? (very new to VBA)

    thanks in advance

  2. #2
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: selecting a random value in an array under a condition

    Its hard to see what you are doing with out your code.
    but maybe something like this helps?

    a 26 times loop and using round and random function to pick plants and put in the array.

    Please Login or Register  to view this content.
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  3. #3
    Registered User
    Join Date
    03-01-2019
    Location
    Mansfield
    MS-Off Ver
    2013
    Posts
    19

    Re: selecting a random value in an array under a condition

    that was actually really helpful, thank you!

+ 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. Replies: 2
    Last Post: 07-24-2018, 03:47 AM
  2. [SOLVED] Selecting random AND unique cell values from an array
    By guillm in forum Excel General
    Replies: 2
    Last Post: 06-28-2017, 08:52 AM
  3. Selecting random rows
    By anar_baku in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-08-2006, 07:45 AM
  4. Selecting Random Data
    By Willie in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 04:05 PM
  5. [SOLVED] Selecting Random Data
    By Willie in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 PM
  6. Selecting Random Data
    By Gary L Brown in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-06-2005, 04:05 AM
  7. [SOLVED] Selecting Random Data
    By Willie in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 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