fixing code populate data in listbox based on all of columns sheet instead of specific columns

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hello
i got this code from this link
VBA Combobox options to be filtered by three other comboboxes
I try amending to show all of columns in listbox but I failed so my data in sheet begins from a2: e and the code populate column a,b,c
VBA Code:
Private Sub UserForm_Initialize()
   Dim Ary As Variant, x As Variant
   Dim i As Long
 
   Set UfDic = CreateObject("scripting.dictionary")
   With Sheets("codes")
      Ary = .Range("A2:e" & .Range("A" & Rows.Count).End(xlUp).Row).Value2
   End With
   For i = 1 To UBound(Ary)
      If Not UfDic.Exists(Ary(i, 1)) Then UfDic.Add Ary(i, 1), CreateObject("scripting.dictionary")
      If Not UfDic(Ary(i, 1)).Exists(Ary(i, 2)) Then UfDic(Ary(i, 1)).Add Ary(i, 2), CreateObject("scripting.dictionary")
      If Not UfDic(Ary(i, 1))(Ary(i, 2)).Exists(Ary(i, 3)) Then UfDic(Ary(i, 1))(Ary(i, 2)).Add Ary(i, 3), CreateObject("scripting.dictionary")
      If Not UfDic(Ary(i, 1))(Ary(i, 2))(Ary(i, 3)).Exists(Ary(i, 4)) Then
         UfDic(Ary(i, 1))(Ary(i, 2))(Ary(i, 3)).Add Ary(i, 4), Application.Transpose(Array(Ary(i, 1), Ary(i, 2), Ary(i, 3), (Ary(i, 4)), (Ary(i, 5))))
       
      Else
         x = UfDic(Ary(i, 1))(Ary(i, 2))(Ary(i, 3))(Ary(i, 4))
         ReDim Preserve x(1 To 5, 1 To UBound(x, 2) + 1)
         x(1, UBound(x, 2)) = Ary(i, 1)
         x(2, UBound(x, 2)) = Ary(i, 2)
         x(3, UBound(x, 2)) = Ary(i, 3)
         x(4, UBound(x, 2)) = Ary(i, 4)
         x(5, UBound(x, 2)) = Ary(i, 5)
       
         UfDic(Ary(i, 1))(Ary(i, 2))(Ary(i, 3))(Ary(i, 4)) = x
      End If
   Next i
   Me.ComboBox1.List = UfDic.Keys
End Sub
I would truly appreciate if anybody help
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
So lets just forget about code that does not work.
So if I understand you want all the values in the active sheet
Columns 1 to 5 loaded into a Listbox on your active sheet

And the listbox is named Listbox1.

Try this:
VBA Code:
Private Sub CommandButton1_Click()
'Modified  12/12/2020  1:02:31 PM  EST
ListBox1.Clear
ListBox1.ColumnCount = 5
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
ListBox1.List = Range("A1:E" & Lastrow).Value
End Sub
 
Upvote 0
if you check the link you understand what I want I have four combobox linked with each of them when I select the combobox4 it should populate data in listbox whole columns but the code designs for 3 columns
 
Upvote 0
if you check the link you understand what I want I have four combobox linked with each of them when I select the combobox4 it should populate data in listbox whole columns but the code designs for 3 columns
I never click on links and look at code and then try to modify code to do what questioner here wants.
This is beyond my knowledgebase.
I will continue to monitor this thread to see what I can learn.
 
Upvote 0
ok if you have alternative it 's ok but to you understand how userform works I have four combobox each of them are linked when I select from combobox 1 based on column a it shows data in combobox2 based on column b and when I select from combobox 2 show data in combobox3 based on column c and when I select from combobox 3 show data in combobox4 based on column d and when I select from combobox 4 then populate all of data (all columns) in listbox based on selection four combobox
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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