本文介绍了RowSource属性错误VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写代码,将输入范围转换为数组,然后将该数组输入表单中的列表框的RowSource中.
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.
根据MSDN,列表/组合框的"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:
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
这篇关于RowSource属性错误VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!