Private Sub CancelButton_Click()
Sheets("User Interface").Select
Unload Me
End Sub
Private Sub OKButton_Click()
Sheets("Fax Form").Select
Unload Me
End Sub
Private Sub UserForm_Initialize()
Sheets("Fax Form").Select
Range("J1").Select
Selection.ClearContents
Sheets("Customers").Select
Dim IRange As Range
Dim ORange As Range
'Find the size of today's dataset
FinalRow = Cells(65536, 1).End(xlUp).Row
NextCol = Cells(1, 255).End(xlToLeft).Column + 2
'Set up output range. Copy heading from D1 there
Range("E1").Copy Destination:=Cells(1, NextCol)
Set ORange = Cells(1, NextCol)
'Define the Input Range
Set IRange = Range("A1").Resize(FinalRow, NextCol - 2)
'Do the Advanced Filter to get unique list of customers
IRange.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=ORange, Unique:=True
'Determine how many unique customers we have
LastRow = Cells(65536, NextCol).End(xlUp).Row
'Sort the data
Cells(1, NextCol).Resize(LastRow, 1).Sort Key1:=Cells(1, NextCol), _
Order1:=xlAscending, Header:=xlYes
With Me.lbCust
.RowSource = ""
.List = Cells(2, NextCol).Resize(LastRow - 1, 1).Value
'Place the ListIndex into cell a10
End With
Sheets("Fax Form").Select
Range("J1").Select
lbCust.ControlSource = "j1"
lbCust.BoundColumn = 0
Sheets("Customers").Select
'Erase the temporary list of customers
Cells(1, NextCol).Resize(LastRow, 1).Clear
End Sub