我是一个相对无知的程序员,很抱歉。应用程序定义或对象定义的错误,血腥的奥秘
Excel 2010 UserForm命令按钮的下列代码返回应用程序定义或对象定义的错误。
Private Sub CommandButton1_Click()
Dim y, vfx, sapx, prx As String
y = Sheets(ComboBox1.Value).Range("B:B").Find(ComboBox2.Value).Row
vfx = Sheets(ComboBox1.Value).Range("1:1").Find("Vendor No").Column
sapx = Sheets(ComboBox1.Value).Range("1:1").Find("SAP Number").Column
prx = Sheets(ComboBox1.Value).Range("1:1").Find("Amey Price").Column
Lrow = Sheets("Macropage").Range("B:B")(Rows.Count).End(xlUp).Row
Userow = Lrow + 1
Sheets("Macropage").Range("A" & Userow) = ComboBox1.Value
Sheets("Macropage").Range("B" & Userow) = ComboBox2.Value
Sheets("Macropage").Range("C" & Userow) = Sheets(ComboBox1.Value).Cells(y, vfx).Value
Sheets("Macropage").Range("D" & Userow) = Sheets(ComboBox1.Value).Cells(y, sapx).Value
Sheets("Macropage").Range("E" & Userow) = Sheets(ComboBox1.Value).Cells(y, prx).Value
Sheets("Macropage").Range("A3:E" & Userow).Columns.AutoFit
Unload UserForm1
End Sub
导致错误的代码看起来是:Sheets(ComboBox1.Value).Cells(y, prx).Value
我通过在一个MsgBox粘它验证。
prx
引用的列唯一不同的地方是它包含小数而不是一些文本。我不明白为什么这应该是一个问题,但。
任何感兴趣的信息,即使它只是关于应用程序定义或对象定义的错误的性质。从谷歌搜索它似乎只是意味着即使编译器认为它是好的,Excel执行脚本时仍有问题。
你确定'prx'有一个值吗?我会在该线上放置一个断点,并查看它在本地窗口中的价值。 –
而且,如果它没有价值,我的猜测是没有列“Amey价格”。 –
'Dim y,vfx,sapx,prx As String' - 与您的问题无关,但您意识到只有'prx'实际上被声明为'String'的权利?其他人被隐式声明为“变体”。 –