[I]Private Sub UserForm_Initialize[/I]()
Call SetUp
Call SortTheDataByDate
Call SortTheDataByBatch
Call GetUniqueBatchNumbers
Call PopulateRB_BatchView
End Sub
[I]Private Sub SetUp[/I]() 'remember to declare these variables as public in standard module
Set wsData = Sheets("Financial_Input, Sheet12")
Set rngFull = wsData.Range("A1").CurrentRegion
Set rngData = rngFull.Offset(1).Resize(rngFull.Rows.Count - 1)
Set wsTemp = Sheets.Add(After:=Sheets(Sheets.Count))
End Sub
[I]Private Sub GetUniqueBatchNumbers[/I]()
wsTemp.Cells.Clear
rngFull.AutoFilter
rngData.Offset(, 1).Resize(, 1).Copy wsTemp.Cells(1, 1)
wsTemp.Range("A:A").RemoveDuplicates Columns:=1, Header:=xlNo
lst_RB_Batches.List = wsTemp.Cells(1, 1).CurrentRegion.Value
End Sub
[I]Private Sub lst_RB_Batches_Change[/I]()
rngFull.AutoFilter Field:=2, Criteria1:=lst_RB_Batches.Value
Call PopulateRB_BatchViewWithFilteredData
End Sub
[I]Private Sub PopulateRB_BatchViewWithFilteredData[/I]()
wsTemp.Cells.Clear
rngFull.SpecialCells(xlCellTypeVisible).Copy wsTemp.Cells(1, 1)
lst_RB_BatchView.List = wsTemp.Cells(1, 1).CurrentRegion.Value
End Sub
[I]Private Sub SortTheDataByBatch[/I]()
With rngFull
.AutoFilter
.Parent.Sort.SortFields.Clear
.Sort key1:=.Cells(2, "B"), order1:=xlAscending, Header:=xlYes
End With
End Sub
[I]Private Sub SortTheDataByDate[/I]()
With rngFull
.AutoFilter
.Parent.Sort.SortFields.Clear
.Sort key1:=.Cells(2, "V"), order1:=xlAscending, Header:=xlYes
End With
End Sub
[I]Private Sub PopulateRB_BatchView[/I]()
With lst_RB_BatchView
.ColumnCount = rngFull.Columns.Count
.List = rngFull.Value
End With
End Sub
[I]Private Sub DeleteTempSheet[/I]()
Application.DisplayAlerts = False
wsTemp.Delete
Application.DisplayAlerts = True
End Sub