Listbox Rowsource...

m0atz

Board Regular
Joined
Jul 17, 2008
Messages
247
Hi all,

just a quick one regarding the rowsource of a multicolumn listbox in my userform.

i want the rowsource to show only the cells autofiltered in my "Data" column. Col A:C is where my 'table' of info sits, and i filter out values in Col A, how do i get the rowsource to reflect only these values?

Cheers
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
You would need to loop through the cells in the range, test their visibility and add them to the ListBox if True. You could do that in the UserForm's Initialize event procedure.
 
Upvote 0

m0atz

Board Regular
Joined
Jul 17, 2008
Messages
247
ADVERTISEMENT
If cannabalised other posts I've found to come up with the following code: I just dont seem to be able to get 3 columns displayed - not sure which bit to tweak to achieve that...do you have any ideas?

Code:
Private Sub UserForm_Initialize()
Dim wks As Worksheet
Dim RngF As Range
Dim RngV As Range
Dim myCell As Range
Set wks = Worksheets("Sheet1")
With wks
 
    Set RngF = .AutoFilter.Range
 
    Me.ListBox1.RowSource = ""
 
            If RngF.Columns(1).Cells.SpecialCells(xlCellTypeVisible).Cells.Count = 1 Then
            MsgBox ("No customer selected")
            Else
 
                With RngF
                    Set RngV = .Resize(.Rows.Count - 1, 1).Offset(1, 0).Cells.SpecialCells(xlCellTypeVisible)
                End With
 
                    For Each myCell In RngV.Cells
                        Me.ListBox1.AddItem myCell.Offset(0, 1).Value
                    Next myCell
            End If
 
End With
End Sub
 
Upvote 0

Kenneth Hobson

Well-known Member
Joined
Feb 6, 2007
Messages
3,181
Office Version
  1. 365
Platform
  1. Windows
You will need to use Columns or add by List(x, y).

Post a sample xls to a free shared site like 4shared.com if needed.
 
Upvote 0

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Instead of:

Code:
Me.ListBox1.AddItem myCell.Offset(0, 1).Value
try:

Code:
With Me.ListBox1
    .AddItem myCell.Offset(0, 1).Value
    .List(.ListCount - 1, 1) = myCell.Offset(0, 2).Value
    .List(.ListCount - 1, 2) = myCell.Offset(0, 3).Value
End With


 
Upvote 0

m0atz

Board Regular
Joined
Jul 17, 2008
Messages
247
Spot on - problem solved - thanks so much for the time and effort - appreciated.

colin
 
Upvote 0

Forum statistics

Threads
1,195,581
Messages
6,010,574
Members
441,557
Latest member
Jbest23

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