This was done on 2010 / w7, but my target is 2003 /w7.
My program is operational but not elegant. So I decided to work things into it as I learn more. I like Pivot Tables but love Advance Filters. However, one of the primary uses for Advance Filters in my application would be to propagate Userform Listboxes.
Reading Bill Jelen book on VBA and Macros, I got most of what I needed, but he never transfers the data to a listbox (that I saw in the examples.).
I've attached my code - The code I use to propagate a ComboBox on the spreadsheet works fine, but can't get it to do the same on the Userform.
My program is operational but not elegant. So I decided to work things into it as I learn more. I like Pivot Tables but love Advance Filters. However, one of the primary uses for Advance Filters in my application would be to propagate Userform Listboxes.
Reading Bill Jelen book on VBA and Macros, I got most of what I needed, but he never transfers the data to a listbox (that I saw in the examples.).
I've attached my code - The code I use to propagate a ComboBox on the spreadsheet works fine, but can't get it to do the same on the Userform.
Code:
Sub Uniqueteamplayer()
Dim ws As Worksheet
Dim wb As Workbook
Dim IRange As Range
Dim ORange As Range
Dim cRange As Range
' Core of code from VBA and Marcos by Bill Jelen
' Some for Microsoft help
' Variant to contain the data to be placed in the listbox
Dim VaData As Variant
' Initialize the Excel Objects
Set wb = ThisWorkbook
Set ws = wb.Worksheets("ResultsData")
With ws
' Find the size of dataset
FinalRow = .Cells(Rows.Count, 1).End(xlUp).Row
nextcol = .Cells(6, Columns.Count).End(xlToLeft).Column + 6
' Set up the Output Range for Criteria data
.Cells(1, nextcol).Value = "Player"
.Cells(1, nextcol + 1).Value = "Grp"
.Cells(1, nextcol + 2).Value = "Tot"
.Cells(2, nextcol).Value = "<>aaBlind"
.Cells(2, nextcol + 1).Value = ""
.Cells(2, nextcol + 2).Value = 0
' Set up Criteria Range
Set cRange = .Cells(1, nextcol).Resize(2, 3)
' Setup output range for report / group
.Cells(4, nextcol).Value = "Player"
Set ORange = .Cells(4, nextcol)
' Define the Input Range
Set IRange = .Range("a6").Resize(FinalRow - 5, nextcol - 6)
' Do the Advanced Filter to get unique list of players for the group
IRange.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=cRange, _
CopyToRange:=ORange, unique:=True
' Store the unique values in VaData
VaData = .Range(.Range("ap5"), .Range("ap500").End(xlUp))
.Range(.Range("ap5"), .Range("ap500").End(xlUp)).Name = "teams"
End With
' Code to place VaData into combobox on spreadsheet as a test
With ws.OLEObjects("Listbox1").Object
.Clear
.List = VaData
.ListIndex = -1
End With
' Clean up the contents of the temporary data storage
With ws
.Range(.Range("ap4"), .Range("ap500").End(xlUp)).ClearContents
End With
End Sub