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
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