How to populate listbox1 and 2

DB73

Board Regular
Joined
Jun 7, 2022
Messages
107
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2010
  6. 2007
Platform
  1. Windows
  2. Mobile
  3. Web
Hi Peeps,

New question 😇
got an userform with 2 listboxes
listbox1
listbox2

i want to populate the 2 listboxes from the same table but in listbox1 with column ABC
and in listbox2 column XYZ
now, already got it working for listbox1, but i aint gettin data in listbox2

as u see i did it with columnwidth.
but , as i think about this issue....do i just copy the listbox items from 1 to 2 and set the columnwidth or is it like populate listbox2 as a new one....so many questions 🤔 😵‍💫🥴


after , as i got this working, i'll add some comboxes to filter the data in the listboxes at once....next project😜

this is my code for listbox1;
VBA Code:
Option Explicit

Dim ws As Worksheet, wsTemp As Worksheet
Dim lRow As Long


Private Sub UserForm_Initialize()
   
    Set ws = ThisWorkbook.Sheets("Dump stats")
    Set wsTemp = ThisWorkbook.Sheets("Temp")

    PopulateListBox1
  
     With ListBox1
        .ColumnHeads = True
        .ColumnCount = 56
        .ColumnWidths = "0;45;0;0;0;0;0;62;50;0;0;60;0;170;80;0;0;100;0;0;0;0;0;65;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;110;90;110"
        .RowSource = "dumpstats"
End With
End Sub

Private Sub commandbutton1_Click()
    wsTemp.Cells.Clear
    Factuur4Weken.Hide
   
End Sub

Private Sub PopulateListBox1()

    wsTemp.Cells.Clear
  
    Dim rng As Range
  
    With ws
        .AutoFilterMode = False
      
        lRow = .Range("A" & .Rows.Count).End(xlUp).Row
      
        If lRow = 1 Then
            Set rng = .Range("A2:BD2")
        Else
            Set rng = .Range("A2:BD" & lRow)
        End If
      

        .Rows(1).Copy wsTemp.Rows(1)
        rng.Copy wsTemp.Range("A2")
      
        Application.CutCopyMode = False
      
        wsTemp.ListObjects.Add(xlSrcRange, wsTemp.Range("A1:BD" & lRow), , xlYes).Name = "dumpstats"
    End With
End Sub
 
Last edited:

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,224,824
Messages
6,181,186
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