How to use AddItem for multiple column ListBox

Skippy

Board Regular
Joined
Mar 3, 2002
Messages
194
Can Additem be used to fill a multiple column listbox from a range in a worksheet? The code below shows what I'm trying to do:

Code:
Sub LoadList()
Dim i As Long
Dim lastRow As Long

With Sheets("Raw data Folio (2)")
    .Activate
    lastRow = .Range("AN65536").End(xlUp).Row
    
    For i = lastRow To 2
        If .Range("AN" & i) <> .Range("AN" & i - 1) Then
            ' Add values to same row of multiple column
            ' listbox for the following cells
            ' A(i)
            ' U(i)
            ' K(i)
            ' etc
        End If
    Next i
End With
    
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
From help.
For a multicolumn ListBox or ComboBox, AddItem inserts an entire row, that is, it inserts an item for each column of the control. To assign values to an item beyond the first column, use the List or Column property and specify the row and column of the item.
 
Upvote 0
Norie

I'm unclear on the proper sytnax. Let's say I want to go to the first empty row in the listbox and put values in specified columns
Code:
Sub LoadList() 
Dim i As Long 
Dim lastRow As Long 

With Sheets("Raw data Folio (2)") 
    .Activate 
    lastRow = .Range("AN65536").End(xlUp).Row 
    
    For i = lastRow To 2 Step - 1 
        If .Range("AN" & i) <> .Range("AN" & i - 1) Then 
                test = .Range("A" & i)
                test2 = .Range("U" & i)
                 frmMain.lstSummary.AddItem("test" in column 2)
                 frmMain.lstSummary.Additem("test" in column 4)
         End If 
    Next i 
End With 
    
End Sub
Another option I'm thinking of is to copy values into a contigous range on the ws and use the RowSource property.
 
Upvote 0
Skippy

I think help is pretty clear.

You use AddItem to add a new row and populate the first column, you then use other methods to populate the other columns.
 
Upvote 0
Norie said:
Skippy

I think help is pretty clear.
Not for a novice like myself :oops: . But I finally, figured it out (after trying many permutations):
Code:
    frmMain.lstSummary.AddItem
    frmMain.lstSummary.List(0, 1) = "Converter"
    frmMain.lstSummary.List(0, 2) = "Stock/Make"

Thanks :biggrin:
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,113,999
Members
448,541
Latest member
iparraguirre89

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