After the obvious answer to my previous question regarding filtering by set parameters I have put 2 listboxes on my user form....Because I'm a newbie to VBA playing with pivot tables was a wee bit daunting!...Here's the code I have:
Dim AllCells As Range, Cell As Range
Dim NoDupes As New Collection
Dim NoDupes2 As New Collection
Dim i As Integer, j As Integer
Dim k As Integer, l As Integer
Dim Swap1, Swap2, Item
Set AllCells = Range("C1:C3000"
' find and sort use codes
On Error Resume Next
For Each Cell In AllCells
NoDupes.Add Cell.Value, CStr(Cell.Value)
Next Cell
On Error GoTo 0
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.UseCode.AddItem Item
Next Item
' find and sort the age
Set AllCells = Range("j1:j3000"
On Error Resume Next
For Each Cell In AllCells
NoDupes2.Add Cell.Value, CStr(Cell.Value)
Next Cell
On Error GoTo 0
For k = 1 To NoDupes2.Count - 1
For l = k + 1 To NoDupes2.Count
If NoDupes2(k) > NoDupes2(l) Then
Swap1 = NoDupes2(k)
Swap2 = NoDupes2(l)
NoDupes2.Add Swap1, before:=l
NoDupes2.Add Swap2, before:=k
NoDupes2.Remove k + 1
NoDupes2.Remove l + 1
End If
Next l
Next k
For Each Item In NoDupes2
UserForm1.Age.AddItem Item
Next Item
UserForm1.Show
End Sub
Ok so my question now is - is it possible to have the age list driven by the use code? Once the use code is selected, only the ages listed for that use code are displayed in the age list box?
Thanks again for your help - I'm learning very quickly thanks to the assistance provided by the gurus here!
Dim AllCells As Range, Cell As Range
Dim NoDupes As New Collection
Dim NoDupes2 As New Collection
Dim i As Integer, j As Integer
Dim k As Integer, l As Integer
Dim Swap1, Swap2, Item
Set AllCells = Range("C1:C3000"
' find and sort use codes
On Error Resume Next
For Each Cell In AllCells
NoDupes.Add Cell.Value, CStr(Cell.Value)
Next Cell
On Error GoTo 0
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.UseCode.AddItem Item
Next Item
' find and sort the age
Set AllCells = Range("j1:j3000"
On Error Resume Next
For Each Cell In AllCells
NoDupes2.Add Cell.Value, CStr(Cell.Value)
Next Cell
On Error GoTo 0
For k = 1 To NoDupes2.Count - 1
For l = k + 1 To NoDupes2.Count
If NoDupes2(k) > NoDupes2(l) Then
Swap1 = NoDupes2(k)
Swap2 = NoDupes2(l)
NoDupes2.Add Swap1, before:=l
NoDupes2.Add Swap2, before:=k
NoDupes2.Remove k + 1
NoDupes2.Remove l + 1
End If
Next l
Next k
For Each Item In NoDupes2
UserForm1.Age.AddItem Item
Next Item
UserForm1.Show
End Sub
Ok so my question now is - is it possible to have the age list driven by the use code? Once the use code is selected, only the ages listed for that use code are displayed in the age list box?
Thanks again for your help - I'm learning very quickly thanks to the assistance provided by the gurus here!