|
Private Sub CommandButton1_Click()
Sheet1.Columns(3).ClearContents
MyLatRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
If MyLatRow = 1 Then GoTo Line100
MyArr = Sheet1.Range("A1:A" & MyLatRow)
Dim Dic As Object
Set Dic = CreateObject("Scripting.Dictionary")
For i = 1 To MyLatRow
Dic(InStr(MyArr(i, 1), "X")) = Dic(InStr(MyArr(i, 1), "X")) + MyArr(i, 1) & "│"
Next i
For i = 1 To Dic.Count
kk = Dic(Application.Small(Dic.keys, i))
kk = Left(kk, Len(kk) - 1) '这个数组最后一个是空值,要剔除
kk = Split(kk, "│")
hh = Application.Transpose(MySort(kk))
MyLatRow = Sheet1.Cells(Rows.Count, 3).End(xlUp).Row
Sheet1.Cells(MyLatRow, 3).Resize(UBound(hh), 1) = hh
Next
Exit Sub
Line100:
Sheet1.Cells(1, 1) = Sheet1.Cells(1, 1)
End Sub
Function MySort(MyArr)
M = 0
For i = 0 To UBound(MyArr) - 1
If MyArr(i) <= MyArr(i + 1) Then
If i > M Then
M = i
Else
i = M
End If
GoTo kk:
Else
x = MyArr(i)
MyArr(i) = MyArr(i + 1)
MyArr(i + 1) = x
If i <> 1 Then i = i - 2
End If
kk:
Next i
MySort = MyArr
End Function
|
|