问题
I can't figure out why this line is throwing the "Error 1004: Application Defined or Object Defined error"? Can someone help?
The object "CombQTY" is a combo box in a userform "MASTER". I am trying to populate the drop down menu of this combo box with the range "QTY_range" (size is 31 rows of numbers in a column = 0,1,2,3,..30).
I have tried swapping the "Userform" with "MASTER" and vice versa.
Private Sub Userform_Initialize()
MASTER.CombQTY.List = Worksheets("RANGES").Range("QTY_range").Value
End Sub
I can't understand why its throwing that error because I don't see any problem with this code. Please help
回答1:
Not directly answering your question, but relative to what you're doing (we don't see what QTE_range
address is).
I tend to loop and collect a list, so i don't have to worry about the dimensions of my named range (more columns than rows).. .example code (untested):
dim i as range, a as range, arr as variant
set a = thisworkbook.names("QTE_range").referstorange
for each i in a
if arr(ubound(arr)) <> "" then redim preserve arr(ubound(arr)+1)
arr(ubound(arr)) = i.value
next
Me.CombQTY.List = arr
Note the references... userform is Me
and workbook is thisworkbook
, which could be antoher ref, or to a sheet name, etc.
来源:https://stackoverflow.com/questions/55836386/error-1004-initializing-a-userform-object