Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6176843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:10:19+00:00 2026-05-24T00:10:19+00:00

I’m facing this weird issue with Scripting.Dictionary object in my VBA code. I wish

  • 0

I’m facing this weird issue with Scripting.Dictionary object in my VBA code. I wish to continue to iterate over the dictionary for its total length. I may add more items to the dictionary within the loop, so the size of the dictionary changes dynamically, so to speak. It seems that it only iterates over for as many elements originally in the dictionary and NOT the new ones!!

Here’s the code:

'Recursively continue to get all dependencies

    numberOfPreReqsToIterate = preReqGraph.Count - 1
    For preReqCount = 0 To numberOfPreReqsToIterate
        listOfPreReqs = preReqGraph.items
        rowNumberOfDependency = Application.WorksheetFunction.Match(listOfPreReqs(preReqCount), Range("requirementNumber"), 0)
        listOfPreReqsForCurrentPreReq = Application.WorksheetFunction.Index(Range("preReqList"), rowNumberOfDependency)

        If listOfPreReqsForCurrentPreReq <> "" Then
            preReqs = Split(listOfPreReqsForCurrentPreReq, ",")

            'Add each prereq to dictionary
            For i = 0 To UBound(preReqs)

                'If prereq already exists implies cycle in graph
                If preReqGraph.Exists(Trim(preReqs(i))) Then
                    MsgBox ("YOU HAVE A CYCLE IN PREREQUISTE SPECIFICATION!")
                    End
                End If

                'If not then add it to the preReqGraph. The value for the key is the key itself
                preReqGraph.Add Trim(preReqs(i)), Trim(preReqs(i))
                numberOfPreReqsToIterate = numberOfPreReqsToIterate + 1

            Next i
        End If
    Next preReqCount

Conceptually I’m trying to get the entire ‘graph’ of dependencies and also detect a cycle if at all that is the case. I iterate over the cells to find out this graph and see if cycles exist. I need to be able to keep iterating over all items in the dictionary for as many items that exist. But it seems excel somehow “precompiles” the for loop so only the original upper bound/limit is taken but not for the new ones! I’ve tried hacking around and this is what I have…but to no avail.

Any ideas?

Attached is a sample of the excel sheet with dummy data…

enter image description here

For R4 the preReqGraph should contain everything from R8 through R17. But What I get is ONLY one level i.e., only R8 through R12 and R14…I’m stumped. I’ve even tried using the LBound and UBound of preReqGraph.items but to no avail.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:10:20+00:00Added an answer on May 24, 2026 at 12:10 am

    The easiest thing to do would be to change your for loop to a while loop and then manually increment your index variable.

    Dim preReqCount as Integer
    preReqCount = 0
    
    While preReqCount <= numberOfPreReqsToIterate
        'Your Loop Logic
    
        preReqCount = preReqCount + 1
    Wend
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have some data like this: 1 2 3 4 5 9 2 6
Does anyone know how can I replace this 2 symbol below from the string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
i got an object with contents of html markup in it, for example: string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.