Populating ListBox. “Run-time error ‘380’: Could not set the List property. Invalid property value.”

I always get error on column 11 when trying to populate ListBox.

I have excel table in sheet Evaluations with test data from B3 to P24. The first 4 columns are text data, remaining 11 columns are numbers between 1 and 100
The first row of the table contains in column 4 text – assessors name that is selected in combobox.

I have created Userform on which I have placed ListBox. I also have a combobox with Assessors names. I want to populate the ListBox only with the records where in column 4 is name of the Assessor selected in combobox.

Upon initializing UserForm I call sub FilterPopulateListBox.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Private Sub FilterPopulateListBox()
Dim PSelectedAssessor As String
PSelectedAssessor = CmbAssessors.Value ' Get the currently selected assessor's name
Dim PWs As Worksheet
Set PWs = ThisWorkbook.Sheets("Evaluations")
Dim PLastRow As Long
PLastRow = PWs.Cells(PWs.Rows.Count, "B").End(xlUp).Row
Dim PData As Range
Set PData = PWs.Range("B3:P" & PLastRow)
' Clear previous entries in the ListBox
With lstEvaluations
.Clear
.ColumnCount = 15 ' Assuming there are 15 columns from B to P
.ColumnWidths = "50;50;50;50;50;50;50;50;50;50;50;50;50;50;50"
Debug.Print lstEvaluations.ColumnCount ' Should print 15
' Loop through each row in the range and add to ListBox if the fourth column matches
Dim PRow As Range
For Each PRow In PData.Rows
If PRow.Cells(1, 4).Value = PSelectedAssessor Then ' Check if fourth column matches the ComboBox
Dim PRowArray() As Variant
PRowArray = Application.Transpose(Application.Transpose(PRow.Value))
.AddItem PRowArray(1) ' Add first column value
Dim i As Integer
For i = 1 To UBound(PRowArray) ' Add other columns
.List(.ListCount - 1, i - 1) = CStr(PRowArray(i))
Next i
End If
Next PRow
End With
End Sub
</code>
<code>Private Sub FilterPopulateListBox() Dim PSelectedAssessor As String PSelectedAssessor = CmbAssessors.Value ' Get the currently selected assessor's name Dim PWs As Worksheet Set PWs = ThisWorkbook.Sheets("Evaluations") Dim PLastRow As Long PLastRow = PWs.Cells(PWs.Rows.Count, "B").End(xlUp).Row Dim PData As Range Set PData = PWs.Range("B3:P" & PLastRow) ' Clear previous entries in the ListBox With lstEvaluations .Clear .ColumnCount = 15 ' Assuming there are 15 columns from B to P .ColumnWidths = "50;50;50;50;50;50;50;50;50;50;50;50;50;50;50" Debug.Print lstEvaluations.ColumnCount ' Should print 15 ' Loop through each row in the range and add to ListBox if the fourth column matches Dim PRow As Range For Each PRow In PData.Rows If PRow.Cells(1, 4).Value = PSelectedAssessor Then ' Check if fourth column matches the ComboBox Dim PRowArray() As Variant PRowArray = Application.Transpose(Application.Transpose(PRow.Value)) .AddItem PRowArray(1) ' Add first column value Dim i As Integer For i = 1 To UBound(PRowArray) ' Add other columns .List(.ListCount - 1, i - 1) = CStr(PRowArray(i)) Next i End If Next PRow End With End Sub </code>
Private Sub FilterPopulateListBox()
    Dim PSelectedAssessor As String
    PSelectedAssessor = CmbAssessors.Value  ' Get the currently selected assessor's name

    Dim PWs As Worksheet
    Set PWs = ThisWorkbook.Sheets("Evaluations")
    Dim PLastRow As Long
    PLastRow = PWs.Cells(PWs.Rows.Count, "B").End(xlUp).Row

    Dim PData As Range
    Set PData = PWs.Range("B3:P" & PLastRow)

    ' Clear previous entries in the ListBox
    With lstEvaluations
        .Clear
        .ColumnCount = 15  ' Assuming there are 15 columns from B to P
        .ColumnWidths = "50;50;50;50;50;50;50;50;50;50;50;50;50;50;50"

    
 Debug.Print lstEvaluations.ColumnCount  ' Should print 15
        
        ' Loop through each row in the range and add to ListBox if the fourth column matches
        Dim PRow As Range
        For Each PRow In PData.Rows
            If PRow.Cells(1, 4).Value = PSelectedAssessor Then  ' Check if fourth column matches the ComboBox
                Dim PRowArray() As Variant
                PRowArray = Application.Transpose(Application.Transpose(PRow.Value))
                .AddItem PRowArray(1)  ' Add first column value
                Dim i As Integer
                For i = 1 To UBound(PRowArray)  ' Add other columns
                    .List(.ListCount - 1, i - 1) = CStr(PRowArray(i))
                Next i
            End If
        Next PRow
    End With
End Sub

on this line of the code

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>.List(.ListCount - 1, i - 1) = CStr(PRowArray(i))
</code>
<code>.List(.ListCount - 1, i - 1) = CStr(PRowArray(i)) </code>
.List(.ListCount - 1, i - 1) = CStr(PRowArray(i))

I always get error when i=11

When i=11 the value of PRowArray(i) is 17 and the line
.List(.ListCount – 1, i – 1) = PRowArray(i)

shows error window “Run-time error ‘380’: Could not set the List property. Invalid property value.”

When debugging when I point with cursor at the beginning of the line at .List(.ListCount – 1, i – 1) it says. “Could not get the List property. Invalid argument” but PRowArray(i) is showing value 17
When i is less then 11 it shows eiter ‘Null’ (before executing that line – when the line is highlighted) or value of the PRowArray(i) when the line is extecuted and next line is highlighted.

I have ensured that listbox has 15 columns
I have nested PRowArray(i) into CStr(PRowArray(i)) to solve if there were some I don’t know what issues with data
I have debugged the code to see what kind of values the code reads for i 1 to 11. It all reads correctly even when i=11 and I point to PRowArray(i) the value is correctly 17

I read forums
I asked ChatGpt3.5

  • There is a limit for unbound data source. The max cols is 10.

  • Try to use an array to populate the listbox which has more than 10 cols.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Option Explicit
Private Sub FilterPopulateListBox()
Dim PSelectedAssessor As String
PSelectedAssessor = CmbAssessors.Value ' Get the currently selected assessor's name
Dim PWs As Worksheet
Set PWs = ThisWorkbook.Sheets(1)
Dim PLastRow As Long
PLastRow = PWs.Cells(PWs.Rows.Count, "B").End(xlUp).Row
Dim PData As Range
Set PData = PWs.Range("B3:P" & PLastRow)
Dim arrRes(), iR As Long, i As Integer
ReDim arrRes(1 To 15, 1 To PData.Rows.Count)
' Clear previous entries in the ListBox
With lstEvaluations
.Clear
.ColumnCount = 15 ' Assuming there are 15 columns from B to P
.ColumnWidths = "50;50;50;50;50;50;50;50;50;50;50;50;50;50;50"
Debug.Print lstEvaluations.ColumnCount ' Should print 15
' Loop through each row in the range and add to ListBox if the fourth column matches
Dim PRow As Range
For Each PRow In PData.Rows
If PRow.Cells(1, 4).Value = PSelectedAssessor Then ' Check if fourth column matches the ComboBox
Dim PRowArray() As Variant
PRowArray = Application.Transpose(Application.Transpose(PRow.Value))
iR = iR + 1
For i = 1 To UBound(PRowArray) ' Add other columns
arrRes(i, iR) = CStr(PRowArray(i))
Next i
End If
Next PRow
ReDim Preserve arrRes(1 To 15, 1 To iR)
.Column = arrRes
End With
End Sub
</code>
<code>Option Explicit Private Sub FilterPopulateListBox() Dim PSelectedAssessor As String PSelectedAssessor = CmbAssessors.Value ' Get the currently selected assessor's name Dim PWs As Worksheet Set PWs = ThisWorkbook.Sheets(1) Dim PLastRow As Long PLastRow = PWs.Cells(PWs.Rows.Count, "B").End(xlUp).Row Dim PData As Range Set PData = PWs.Range("B3:P" & PLastRow) Dim arrRes(), iR As Long, i As Integer ReDim arrRes(1 To 15, 1 To PData.Rows.Count) ' Clear previous entries in the ListBox With lstEvaluations .Clear .ColumnCount = 15 ' Assuming there are 15 columns from B to P .ColumnWidths = "50;50;50;50;50;50;50;50;50;50;50;50;50;50;50" Debug.Print lstEvaluations.ColumnCount ' Should print 15 ' Loop through each row in the range and add to ListBox if the fourth column matches Dim PRow As Range For Each PRow In PData.Rows If PRow.Cells(1, 4).Value = PSelectedAssessor Then ' Check if fourth column matches the ComboBox Dim PRowArray() As Variant PRowArray = Application.Transpose(Application.Transpose(PRow.Value)) iR = iR + 1 For i = 1 To UBound(PRowArray) ' Add other columns arrRes(i, iR) = CStr(PRowArray(i)) Next i End If Next PRow ReDim Preserve arrRes(1 To 15, 1 To iR) .Column = arrRes End With End Sub </code>
Option Explicit
Private Sub FilterPopulateListBox()
    Dim PSelectedAssessor As String
    PSelectedAssessor = CmbAssessors.Value  ' Get the currently selected assessor's name
    Dim PWs As Worksheet
    Set PWs = ThisWorkbook.Sheets(1)
    Dim PLastRow As Long
    PLastRow = PWs.Cells(PWs.Rows.Count, "B").End(xlUp).Row
    Dim PData As Range
    Set PData = PWs.Range("B3:P" & PLastRow)
    Dim arrRes(), iR As Long, i As Integer
    ReDim arrRes(1 To 15, 1 To PData.Rows.Count)
    ' Clear previous entries in the ListBox
    With lstEvaluations
        .Clear
        .ColumnCount = 15  ' Assuming there are 15 columns from B to P
        .ColumnWidths = "50;50;50;50;50;50;50;50;50;50;50;50;50;50;50"
        Debug.Print lstEvaluations.ColumnCount  ' Should print 15
        ' Loop through each row in the range and add to ListBox if the fourth column matches
        Dim PRow As Range
        For Each PRow In PData.Rows
            If PRow.Cells(1, 4).Value = PSelectedAssessor Then  ' Check if fourth column matches the ComboBox
                Dim PRowArray() As Variant
                PRowArray = Application.Transpose(Application.Transpose(PRow.Value))
                iR = iR + 1
                For i = 1 To UBound(PRowArray)  ' Add other columns
                    arrRes(i, iR) = CStr(PRowArray(i))
                Next i
            End If
        Next PRow
        ReDim Preserve arrRes(1 To 15, 1 To iR)
        .Column = arrRes
    End With
End Sub

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật