Runtime Error 380 for listbox on userform

newbieX

New Member
Joined
Jul 24, 2013
Messages
35
I have a button that when clicked populates a listbox from a sheet ("Data") based on a filter set by a value in a textbox (TextBox1) on the userform. The code seems to bomb out at the line below regardless of what column I enter. It appears that maybe it doesn't want to go above 9 for some reason.

Code:
        ListBox1.List(s, 10) = Cells(sat, "K")

The function that is called when the button is clicked is below.

Code:
Private Sub ListBox1AFill()
Dim sat, s As Long
Dim deg1, deg2 As String

With ListBox1
    .Clear
    .ColumnCount = 13
    .ColumnWidths = "70;140;40;45;45;45;40;40;40;50;50;150;50"
End With

deg2 = TextBox1.value
Debug.Print deg2
For sat = 2 To Cells(65536, "A").End(xlUp).Row
    Set deg1 = Cells(sat, "A")
    Debug.Print deg1
    Debug.Print s
    If deg1 = deg2 Then
        ListBox1.AddItem
        ListBox1.List(s, 0) = Cells(sat, "A")
        ListBox1.List(s, 1) = Cells(sat, "B")
        ListBox1.List(s, 2) = Cells(sat, "C")
        ListBox1.List(s, 3) = Cells(sat, "D")
        ListBox1.List(s, 4) = Cells(sat, "E")
        ListBox1.List(s, 5) = Cells(sat, "F")
        ListBox1.List(s, 6) = Cells(sat, "G")
        ListBox1.List(s, 7) = Cells(sat, "H")
        ListBox1.List(s, 8) = Cells(sat, "I")
        ListBox1.List(s, 9) = Cells(sat, "J")
        ListBox1.List(s, 10) = Cells(sat, "K")
        ListBox1.List(s, 11) = Cells(sat, "L")
        ListBox1.List(s, 12) = Cells(sat, "M")
        s = s + 1
    End If: Next
For s = 1 To 13
    Controls("TextBox" & s) = ""
Next
End Sub

I Initialize the Listbox when form is opened:

Code:
'MultiPage1.Pages("Page1").Visible = True
ListBox1.ColumnWidths = "70;140;40;45;45;45;40;40;40;50;50;150;50"
ListBox1.ColumnCount = 13
ListBox1.List = Sheets("Data").Range("A2:M" & [a65536].End(3).Row).value

'MultiPage1.Pages("Page1").Visible = True
TextBox15.value = ListBox1.ListCount

If I change the counter to 9, column count to 10, and do not add the last 3 columns to my If statement, the listbox populates correctly.

Ideas anyone?

Runtime error 380 states that it could not set the List Property as it is an invalid property value. It doesn't seen to like values above 9.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
I have a button that when clicked populates a listbox from a sheet ("Data") based on a filter set by a value in a textbox (TextBox1) on the userform. The code seems to bomb out at the line below regardless of what column I enter. It appears that maybe it doesn't want to go above 9 for some reason.

Code:
        ListBox1.List(s, 10) = Cells(sat, "K")

The function that is called when the button is clicked is below.

Code:
Private Sub ListBox1AFill()
Dim sat, s As Long
Dim deg1, deg2 As String

With ListBox1
    .Clear
    .ColumnCount = 13
    .ColumnWidths = "70;140;40;45;45;45;40;40;40;50;50;150;50"
End With

deg2 = TextBox1.value
Debug.Print deg2
For sat = 2 To Cells(65536, "A").End(xlUp).Row
    Set deg1 = Cells(sat, "A")
    Debug.Print deg1
    Debug.Print s
    If deg1 = deg2 Then
        ListBox1.AddItem
        ListBox1.List(s, 0) = Cells(sat, "A")
        ListBox1.List(s, 1) = Cells(sat, "B")
        ListBox1.List(s, 2) = Cells(sat, "C")
        ListBox1.List(s, 3) = Cells(sat, "D")
        ListBox1.List(s, 4) = Cells(sat, "E")
        ListBox1.List(s, 5) = Cells(sat, "F")
        ListBox1.List(s, 6) = Cells(sat, "G")
        ListBox1.List(s, 7) = Cells(sat, "H")
        ListBox1.List(s, 8) = Cells(sat, "I")
        ListBox1.List(s, 9) = Cells(sat, "J")
        ListBox1.List(s, 10) = Cells(sat, "K")
        ListBox1.List(s, 11) = Cells(sat, "L")
        ListBox1.List(s, 12) = Cells(sat, "M")
        s = s + 1
    End If: Next
For s = 1 To 13
    Controls("TextBox" & s) = ""
Next
End Sub

I Initialize the Listbox when form is opened:

Code:
'MultiPage1.Pages("Page1").Visible = True
ListBox1.ColumnWidths = "70;140;40;45;45;45;40;40;40;50;50;150;50"
ListBox1.ColumnCount = 13
ListBox1.List = Sheets("Data").Range("A2:M" & [a65536].End(3).Row).value

'MultiPage1.Pages("Page1").Visible = True
TextBox15.value = ListBox1.ListCount

If I change the counter to 9, column count to 10, and do not add the last 3 columns to my If statement, the listbox populates correctly.

Ideas anyone?

Runtime error 380 states that it could not set the List Property as it is an invalid property value. It doesn't seen to like values above 9.
What is the actual value in Cells(sat, "K") at the point when the code fails?
 
Upvote 0

Forum statistics

Threads
1,215,589
Messages
6,125,695
Members
449,250
Latest member
azur3

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