+ Reply to Thread
Results 1 to 7 of 7

issue with nesting loops

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

    issue with nesting loops

    Hi everyone!

    i'm very new to VBA and i'm having some issues with nested loop structures.

    i'm trying to write down certain values for 30 individuals for 50 days in 2 years. let's suppose i write the following code:

    Please Login or Register  to view this content.

    the values are written only for the innermost loop (only for the final year and final day) and i'm not sure how to get around that. In addition, i would like the loops to calculate the value of plants(p,1) for each individual but for that value to be constant throughout the days in a year. For example if plants(p,1) = 27 for individual number 1, i would like the value of 27 to persist for days 1 to UBday (for individul number 1 only) but to be calculated again as soon as a new year starts. I have tried using a collection to do this and it worked fine but the issue is that i need to later perform some calulations within the array and splitting the collection stores the values as string. I am very new to VBA so I have no clue on how to go about this so any help would be greatly appreciated!

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: issue with nesting loops

    The thing is you need to accound to the last loop too

    Please Login or Register  to view this content.
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

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

    Re: issue with nesting loops

    Hi Keebellah!
    Unfortunately the code you provided results in the same issue even if I place the code just after the day loop instead of after the year loop. Like i mentioned before, I have previously tried to use a colllection
    Please Login or Register  to view this content.
    This code actually ended up doing EXACTLY what i wanted but i later encountered issues due to the values being stored as string rather than numeric values and also, i later need to vary the value of nplants which was also a little problematic in a collection so i guess my question is: can i achieve the outcome of this code without having to use a collection? if a collection is the only option, can i get around the issue of the values being string and the variable limits of the collection changing after the addition of each collection?

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: issue with nesting loops

    Set the Stings to Val( the result here )
    You must however be sure that the content of the result is indeed numeric

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: issue with nesting loops

    Sample file?

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

    Re: issue with nesting loops

    I actually ended up figuring it out but thanks so much anyway!!!

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: issue with nesting loops

    Good of you to let us know.
    Don't forget to mark the post SOLVED

+ 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. Nesting Issue
    By mbeyatli in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 10-07-2014, 02:47 PM
  2. Nesting for loops
    By gatemoon1 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-30-2013, 03:38 PM
  3. [SOLVED] Nesting OR/AND/IF issue
    By Fursmanm in forum Excel General
    Replies: 3
    Last Post: 09-05-2012, 06:40 AM
  4. [SOLVED] Excel 2007 : Nesting Issue
    By wallygator1922 in forum Excel General
    Replies: 5
    Last Post: 07-11-2012, 08:37 PM
  5. Nesting Issue
    By nadjadee in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-07-2012, 10:18 PM
  6. Issue with nesting Sum If
    By repke in forum Excel General
    Replies: 2
    Last Post: 11-30-2008, 11:05 PM
  7. Nesting Loops
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-05-2008, 11:43 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