VBA Error 381 - List Property. Invalid Property Array Index

SSF1590

Board Regular
Joined
Oct 20, 2019
Messages
73
Hello,

I have the following code but is giving me error 381 when I try to run the macro. For now, I have only one entry in my database in column A and over time more will be added. I need combobox1 to give me the list of entries in column A even if I have only or more than one. Can I please have your help to make the below code work as described in the above?

Thank you.


Private Sub UserForm_Initialize()


With Sheets("Database")
Me.ComboBox1.List = .Range("A4", .Range("A" & Rows.Count).End(xlUp)).Value
End With


End Sub
 

Some videos you may like

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

lrobbo314

Well-known Member
Joined
Jul 14, 2008
Messages
3,031
Office Version
  1. 365
Platform
  1. Windows
Try this.

Code:
Private Sub UserForm_Initialize()
With Sheets("Database")
    Me.ComboBox1.RowSource = .Range("A4:A" & .Range("A" & Rows.Count).End(xlUp).Row).Address
End With
End Sub
 
Last edited:

lrobbo314

Well-known Member
Joined
Jul 14, 2008
Messages
3,031
Office Version
  1. 365
Platform
  1. Windows
───────────────────░█▓▓▓█░▇▆▅▄▃▂
──────────────────░█▓▓▓▓▓█░▇▆▅▄▃▂
─────────────────░█▓▓▓▓▓█░▇▆▅▄▃▂
──────────░░░───░█▓▓▓▓▓▓█░▇▆▅▄▃▂ ...
─────────░███░──░█▓▓▓▓▓█░▇▆▅▄▃▂
───────░██░░░██░█▓▓▓▓▓█░▇▆▅▄▃▂
──────░█░░█░░░░██▓▓▓▓▓█░▇▆▅▄▃▂
────░██░░█░░░░░░█▓▓▓▓█░▇▆▅▄▃▂
───░█░░░█░░░░░░░██▓▓▓█░▇▆▅▄▃▂
──░█░░░░█░░░░░░░░█▓▓▓█░▇▆▅▄▃▂
──░█░░░░░█░░░░░░░░█▓▓▓█░▇▆▅▄▃▂
──░█░░█░░░█░░░░░░░░█▓▓█░▇▆▅▄▃▂
─░█░░░█░░░░██░░░░░░█▓▓█░▇▆▅▄▃▂
─░█░░░░█░░░░░██░░░█▓▓▓█░▇▆▅▄▃▂
─░█░█░░░█░░░░░░███▓▓▓▓█░▇▆▅▄▃▂
░█░░░█░░░██░░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
░█░░░░█░░░░█████▓▓▓▓▓█░▇▆▅▄▃▂
░█░░░░░█░░░░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
░█░█░░░░██░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
─░█░█░░░░░████▓▓▓▓██░▇▆▅▄▃▂
─░█░░█░░░░░░░█▓▓██▓█░▇▆▅▄▃▂
──░█░░██░░░██▓▓█▓▓▓█░▇▆▅▄▃▂
───░██░░███▓▓██▓█▓▓█░▇▆▅▄▃▂
────░██▓▓▓███▓▓▓█▓▓▓█░▇▆▅▄▃▂
──────░█▓▓▓▓▓▓▓▓█▓▓▓█░▇▆▅▄▃▂
──────░█▓▓▓▓▓▓▓▓▓▓▓▓▓█░▇▆▅▄▃▂
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,137
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Depending on what you are using the combo for, using RowSource can cause problems.
Another option
Code:
Private Sub UserForm_Initialize()
    Dim Lr As Long

    With Sheets("Database")
        Lr = .Range("A" & Rows.Count).End(xlUp).Row
        If Lr = 4 Then
            Me.ComboBox1.AddItem .Range("A4").Value
        Else
            Me.ComboBox1.List = .Range("A4:A" & Lr).Value
        End If
    End With


End Sub
 

SSF1590

Board Regular
Joined
Oct 20, 2019
Messages
73
Thank you very much Fluff for advising regarding the RowSource. I’ve tried your code and it also works perfectly!

Again, thank you very much.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,137
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,122,940
Messages
5,598,975
Members
414,270
Latest member
skipolmsted

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
Top