Private Sub UserForm_Initialize()
Dim wks as Worksheet
Dim rng As Range
Dim celle As Range
Dim coll As New Collection
Dim i As Long
ListBox1.Clear
set wks = Sheets("Data")
with wks
Set rng = Range(.Cells(2, "M"), .Cells(.Rows.Count, "M").End(xlUp))
with .Sort
with .SortFields
.Clear
.Add Key:=wks.Range("M2"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
end with
.SetRange rng
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
For Each celle In rng
On Error Resume Next
coll.Add CStr(celle), CStr(celle)
Next celle
For i = 1 To coll.Count
frmCriteria.ListBox1.AddItem coll(i)
Next i
End Sub
|