0
    Debug.Print distdic(1813)
For Each Key In storedic.Keys
     NewBook.Sheets("Store Bulletin List").Cells(x, 1).Value = Key
     NewBook.Sheets("Store Bulletin List").Cells(x, 2).Value = distdic(Key)
     Debug.Print distdic(Key)
    x = x + 1
Next

The first debug produces a result but that second debug does not even if the Key is 1813

Why can't I use my distdic from inside the foreach loop?

13
  • is distdic defined in the code before the loop? And isn't the syntax something like distdic.Items(key)? Commented Jan 21, 2016 at 19:02
  • yes, and it's a fully loaded dictionary. Values are in there for sure. Commented Jan 21, 2016 at 19:03
  • first debug works... second debug doesn't Commented Jan 21, 2016 at 19:03
  • see this answer for correct syntax Commented Jan 21, 2016 at 19:07
  • 1
    fixed.. provided answer here for posterity. Thank you for your help. Commented Jan 21, 2016 at 20:19

1 Answer 1

1
        Debug.Print distdic(1813)
For Each Key In storedic.Keys
     NewBook.Sheets("Store Bulletin List").Cells(x, 1).Value = Key
     NewBook.Sheets("Store Bulletin List").Cells(x, 2).Value = distdic(Cint(Key))
     Debug.Print distdic(Cint(Key))
    x = x + 1
Next

Problem was the datatype of the Key. The above fixed it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.