简体   繁体   English

RowSource属性错误VBA

[英]RowSource property error vba

I am trying to write a code that converts an input range into an array, then feeds that array into the RowSource for a listbox in my form. 我正在尝试编写代码,将输入范围转换为数组,然后将该数组输入表单中的列表框的RowSource中。

According to MSDN the "RowSource" property for list/combo box should accept arrays, so I'm not sure why Im getting a runtime error here: 根据MSDN,列表/组合框的“ RowSource”属性应接受数组,因此我不确定为什么我在这里遇到运行时错误:

 Option Explicit

Sub test()
Dim rng As Range
Dim myarray As Variant


Set rng = Worksheets("Sheet1").Range("List")
myarray = RangeToArray(Range("List"))
UserForm1.ListBox1.RowSource = "myarray"


End Sub
Function RangeToArray(inputRange As Range) As Variant
   Dim inputArray As Variant
   inputArray = inputRange.Value

   'operations on inputArray
   '...'

   RangeToArray = inputArray
End Function

尝试UserForm1.ListBox1.List = myarray

According to the Excel VBA help: 根据Excel VBA帮助:

The RowSource property accepts worksheet ranges from Microsoft Excel. RowSource属性接受Microsoft Excel中的工作表范围。

If you have a MSDN link that says otherwise, please post it. 如果您的MSDN链接另有说明,请发布它。

Anyway, to get the result you want, change 无论如何,要获得想要的结果,请更改

UserForm1.ListBox1.RowSource = "myarray"

to

UserForm1.ListBox1.List = myarray

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM