Reputation: 5877
According to this thread: RowSource property error vba
Listbox.rowsource can accept a range.
However when I run this
Option Explicit
Sub test()
UserForm1.ListBox1.RowSource = ActiveSheet.Range("A1:A2")
End Sub
I get a type mismatch error. Could someone please shine some light on what is going on?
Upvotes: 0
Views: 3432
Reputation: 1
I got the same error when I changed my code from having the active sheet with a named range for the RowSource
to a different sheet. You can use the RefersTo
property of a name as follows:
MyUserForm.Listbox1.Rowsource = ThisWorkbook.Names("rangename").RefersTo
If the named range is on the active sheet, then the following will also work:
MyUserForm.Listbox1.Rowsource = "rangename"
But who likes changing the active sheet just to load a listbox?
Upvotes: 0
Reputation: 10715
UserForm1.ListBox1.RowSource takes a string:
Use this: UserForm1.ListBox1.RowSource = ActiveSheet.Name & "!A1:A2"
Upvotes: 1