I'm a relatively uninformed programmer, apologies.
Below code for an Excel 2010 UserForm command button returns a application-defined or object-defined error.
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
The code causing the error appears to be: Sheets(ComboBox1.Value).Cells(y, prx).Value
which I verified by sticking it in a MsgBox.
The only thing different about the column referenced by prx
is it contains decimals rather than some text. I don't see why this should be a problem though.
Any info appreciated, even if it's just about the nature of a application-defined or object-defined error. From googling it only seems to mean Excel has a problem executing the script even if the compiler thinks it is fine.
prx
has a value? I would put a break point on that line, and see what its value is in the locals window.Dim y, vfx, sapx, prx As String
- not related to your issue, but you realize onlyprx
is actually declared as aString
right? The others are implicitly declared asVariant
.