错误1004初始化UserForm对象? [英] Error 1004 Initializing a UserForm object?

查看:59
本文介绍了错误1004初始化UserForm对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么此行会引发错误1004:应用程序定义或对象定义的错误"?有人可以帮忙吗?

I can't figure out why this line is throwing the "Error 1004: Application Defined or Object Defined error"? Can someone help?

对象"CombQTY"是用户窗体"MASTER"中的组合框.我正在尝试使用范围"QTY_range"(大小为一列中的31行数字= 0、1、2、3,.. 30)填充此组合框的下拉菜单.

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

推荐答案

不是直接回答您的问题,而是相对于您所做的事情(我们看不到 QTE_range 地址是什么).

Not directly answering your question, but relative to what you're doing (we don't see what QTE_range address is).

我倾向于循环并收集列表,因此我不必担心命名范围的大小(列多于行).. example代码(未经测试):

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

请注意引用...用户窗体是 Me ,工作簿是 thisworkbook ,可以是其他参考,也可以是工作表名称,等等.

Note the references... userform is Me and workbook is thisworkbook, which could be antoher ref, or to a sheet name, etc.

这篇关于错误1004初始化UserForm对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆