RTE 381 Could not set the List property. Invalid property array index.

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
15,517
Office Version
  1. 365
Platform
  1. Windows
Hi all.

I've just tried populating a set of comboboxes in a form using the code below and I'm getting the message, Runtime Error 381 Could not set the List property. Invalid property array index.

A1:G1 contain the names of the comboboxes, the idea is to populate each of the boxes named in that range with a list found below it. This was just a quick attempt before packing up for the day so it's likely riddled with errors and bad ideas. I'm almost certain that Me.Controls(c.Value).List is wrong, I just don't seem to be able to find the correct way to express that part.

Code:
Private Sub UserForm_Initialize()
Dim rng As Range, c As Range, lRow As Long
With Lists
    Set rng = .Range("A1:G1")

    For Each c In rng
        lRow = .Cells(.Rows.Count, c.Column).End(xlUp).Row
        Me.Controls(c.Value).List = c.Offset(1).Resize(lRow - 1)
    Next c

End With
    Me.Show
End Sub

Any suggestions for a fix, or ways to improve would be appreciated.

Thanks in advance, Jason.
 
VBA Code:
        Me.Controls(c.Value).List = c.Offset(1).Resize(lRow - 1).Value
The List property requires a Variant array, so you need .Value on the RHS to return a Variant array, otherwise it's a Range object.
 
Upvote 0
Solution
Bingo!

Thank you very much, John. I had a feeling that I was missing something simple.
 
Upvote 0

Forum statistics

Threads
1,226,771
Messages
6,192,919
Members
453,767
Latest member
922aloose

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top