为什么我的公共字典会出现1004个错误?

时间:2017-10-18 15:46:14

标签: excel-vba vba excel

我试图建立一个公共字典,以便在使用我的文档时查询各个方面。但是 - 该文件似乎“忘记了”#34;关于分配的字典?我的代码有问题吗?

Dim hedDict As Scripting.Dictionary

Public Function headDict()
On Error Resume Next
Dim i As Long
Dim z As Long
Dim x As Variant
Dim c As Variant
Dim d As Variant
Set hedDict = New Dictionary
z = Range("A1").End(xlToRight).Column
Sheets("New Item Entry").Select
Range("A2").Select
i = 1
Do While i <= z
    c = Columns(i).Rows(1).Value
    d = i
    Call addToDict(hedDict, c, d)
    i = i + 1
Loop
End Function

Function addToDict(dic, iteem, val)
dic.Add iteem, val
End Function

Sub ChckTst()
Dim x as Long
x = Cells(i, hedDict("Order UOM Price")).Value
MsgBox (x)
End Sub

上面的子例程在调用字典之前做了各种其他事情,例如调用过多的变量,分配数组和创建集合。如果这可能会干扰,请告诉我。

谢谢

0 个答案:

没有答案