fill 2 columns with headers in listbox

teodormircea

Active Member
Joined
Jan 8, 2008
Messages
331
Hello forum,

i would like to fill from 2 columns the values in a listbox with the headers also from the excel fille

Here i have the code for 1 column but with out header from excel fille
In listbox properties : i have ColumnCount=2, ColumnHeads=True
Code:
Private Sub UserForm_Initialize()
    Dim cell As Range
    Dim Rng As Range
    
    With ThisWorkbook.Sheets("Sheet1")
        Set Rng = .Range("a2", .Range("a2").End(xlDown))
   End With
    
    For Each cell In Rng.Cells
        Me.ListBox1.AddItem cell.Value
    Next cell
    
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try:

Code:
Private Sub UserForm_Initialize()
    Dim Rng As Range
    With ThisWorkbook.Sheets("Sheet1")
        Set Rng = .Range("A2", .Range("A2").End(xlDown)).Resize(, 2)
        Rng.Name = "List"
    End With
    Me.ListBox1.RowSource = "List"
End Sub
 
Upvote 0
Thanks Andrew
IF I HAVE 2 WORKBOOKS IN SAME TIME OPENED OF COURSE I HAVE EN ERROR, DO I HAVE TO TELL THE LIST BOX FROM WHICH WORKBOOK TO PULL OUT THE INFO

like, if
Code:
Private Sub UserForm_Initialize()
    Dim Rng As Range
    With ThisWorkbook("FILTERS").Sheets("Sheet1")
        Set Rng = .Range("A2", .Range("A2").End(xlDown)).Resize(, 2)
        Rng.Name = "List"
    End With
    Me.ListBox1.RowSource = "List"
End Sub
i'd like to know if is correct
 
Upvote 0
apparently doesn't work with all my macros,
is it a possibility to introduce them by macros and not pull them from an excel file
for exemple this, put them directly in the code
FILTRES .xls
ABCD
1SigneOperateur
2=blank
3<>nonblank
4**contain
operateurs
 
Upvote 0
i made this for the firs column

Code:
Private Sub Userform_Initialize()
   


    ListBox1.AddItem "="
    

    ListBox1.AddItem "<>"
    ListBox1.AddItem "*  *"
 
End Sub
 
Upvote 0
See if you can adapt this:

Code:
Private Sub UserForm_Initialize()
    Dim x As Integer
    Dim y As Integer
    y = 0
    With ListBox1
        For x = 1 To 5
            .AddItem x
            .Column(1, y) = "Item " & x
            y = y + 1
        Next x
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,548
Messages
6,120,141
Members
448,948
Latest member
spamiki

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