Populate Listbox with Unique Values from specific columns

kerober2

New Member
Joined
Jan 25, 2018
Messages
1
Looking to populate Listbox2 with unique values values from Row3 ("A list of activities that each Entity does") but only for columns("Entity") that the user selected in Listbox1. I'm not getting an error but it's not working quite right .... Sorry I am a beginner so my format might be horrible.

Private Sub ListBox1_Click()ListBox2.ClearDim Entity As StringDim myList2 As CollectionDim myRange2 As RangeDim myVal2 As VariantDim m As IntegerDim ColumnId As IntegerEntity = ListBox1.ValueSheets("Database").SelectMyLastCol = LastCol(Sheets("Database").UsedRange)m = MyLastColSet myRange2 = Sheets("Database").Range(Sheets("Database").Cells(2, 3), Sheets("Database").Cells(2, m))Set myList2 = New CollectionOn Error Resume NextFor Each myCell In myRange2.Cells If myCell.Value = Entity Then ColumnId = ActiveCell.Column myList2.Add Cells(3, ColumnId).Value, CStr(Cells(3, ColumnId).Value) Else End IfNext myCellOn Error GoTo 0For Each myVal2 In myList2UserForm5.ListBox2.AddItem myVal2Next myVal2End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Because your code is just a block of text, it's very difficult to tell why you have problems.
However I do notice that you have
Code:
On Error Resume Next
in there. Try removing that & see what happens.
If that doesn't help, try posting your code again, but in a readable manner.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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