Listbox value null

miami2k

Board Regular
Joined
Nov 1, 2017
Messages
58
Dear All,

I have this simple code copied from somewhere else but I can' t check if it works because it stops immediately:

Private Sub CommandButton2_Click()


With Me.ListBox1
.ColumnCount = rRng.Columns.Count
.ColumnWidths = "0,40,50,60,60,0,0,0,0,0,0,0,0,0,0,150,120,100,65,70,50"
.MultiSelect = fmMultiSelectMulti
.ListIndex = -1
End With
With Rng
For i = 1 To .Rows.Count
If .Cells(i, 2) = 2 Then
ListBox2.AddItem .Cells(i, 1).Value
For j = 2 To .Columns.Count
ListBox2.List(ListBox2.ListCount - 1, j - 1) = .Cells(i, j).Value
Next j
End If
Next i
End With


End Sub

Runtime error 424 and Me.ListBox1 returns Null as value, it looks like the listbox is not activated.

How can I solve it?

Apart from that is 1 day that I'm going crazy trying to find a simple code to fill the listbox filtering the rows depending on values of one column.
I undestand that I have 2 options: one is to filter the values of the origin and show only all the ones remaining or the other option is to check line by line the values and add each line.
Do you have any suggestion for a simple solution?


Thank you!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Well that got complicated in a hurry. How about:

Code:
Private Sub CommandButton2_Click()
    RillLbWithRange Me.ListBox1, Range("A1:B3")
End Sub
Sub RillLbWithRange(lb, rng)
    With lb
        .ColumnCount = rng.Columns.Count
        .MultiSelect = fmMultiSelectMulti
        .ListIndex = -1
        .ListFillRange = rng.Address
    End With
End Sub

You will need to do something with the column widths in ListBox1.

PPR - Please Post Results.
 
Upvote 0
if your List box is in a Userform then you need "Rowsource":-
Code:
.RowSource = rng.Address

You could also use:-
Code:
.List = rng.Value
First ensuring there is no Address in the Listbox Code module Properties for the Rowsource/listFillRange
 
Upvote 0
Where do I put this?
I've also tried to replace "With me.ListBox1" with "With UserForm2.ListBox1" but when I run the code the lb is always null. Error 424 Object required!
It looks the same when a sheet is not activated!

Any other working code is accepted.
 
Upvote 0
Do you have a listbox on userform2 called ListBox1?
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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