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.
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
According to the Excel VBA help:
If you have a MSDN link that says otherwise, please post it.
Anyway, to get the result you want, change
to
try
UserForm1.ListBox1.List = myarray