Hey all,
i want to use excel for may query.
I have for example tree columns:
A B C
1 bel long 123
2 bel short 234
3 ned long 345
4 ned short 456
5 bel long 567
6 lux bigg 987
...
I use a userform to select my query:
listbox1, listbox2, listbox3
What I want:
Listbox1 show the unique valuse in column A
that seems to be fine.
Now listbox2 :
When I select in listbox1 example: "bel"
I want listbox2 to show the unique & sorted values "long" & "short"
Listbox3:
show unique & sorted values that meats the value of listbox 1 & 2
in this example listbox2 = "long" then listbox3 = "123" & "567"
Someone ?
Thanks in advance.
i want to use excel for may query.
I have for example tree columns:
A B C
1 bel long 123
2 bel short 234
3 ned long 345
4 ned short 456
5 bel long 567
6 lux bigg 987
...
I use a userform to select my query:
listbox1, listbox2, listbox3
What I want:
Listbox1 show the unique valuse in column A
Code:
sub listbox1 ()
Dim AllCells As Range, Cell As Range
Dim NoDupes As New Collection
Dim i As Integer, j As Integer
Dim Swap1, Swap2, Item
Set AllCells = Range("A1:A105")
On Error Resume Next
For Each Cell In AllCells
NoDupes.Add Cell.Value, CStr(Cell.Value)
Next Cell
On Error GoTo 0
With UserForm1
.Label1.Caption = "Total Items: " & AllCells.Count
.Label2.Caption = "Unique Items: " & NoDupes.Count
End With
For i = 1 To NoDupes.Count - 1
For j = i + 1 To NoDupes.Count
If NoDupes(i) > NoDupes(j) Then
Swap1 = NoDupes(i)
Swap2 = NoDupes(j)
NoDupes.Add Swap1, before:=j
NoDupes.Add Swap2, before:=i
NoDupes.Remove i + 1
NoDupes.Remove j + 1
End If
Next j
Next i
For Each Item In NoDupes
UserForm1.ListBox1.AddItem Item
Next Item
UserForm1.Show
End Sub
Now listbox2 :
When I select in listbox1 example: "bel"
I want listbox2 to show the unique & sorted values "long" & "short"
Listbox3:
show unique & sorted values that meats the value of listbox 1 & 2
in this example listbox2 = "long" then listbox3 = "123" & "567"
Someone ?
Thanks in advance.