为什么我不能从foreach循环中引用另一个字典? VBA

时间:2016-01-21 19:00:22

标签: vba dictionary foreach

    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

第一次调试产生结果 但即使密钥是1813

,第二次调试也不会

为什么我不能在foreach循环中使用我的distdic?

1 个答案:

答案 0 :(得分: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

问题是密钥的数据类型。以上修正了它。

相关问题