'给你加了一个条件,就是13楼的,,,
Option Explicit
Sub test()
Dim arr, i, j, p, dic
Set dic = CreateObject("scripting.dictionary")
arr = Split("XS,S,M,L,XL,2XL,3XL,4XL", ",")
For i = 0 To UBound(arr)
dic(arr(i)) = i - 20
Next
arr = [a1].CurrentRegion.Offset(1).Resize(, 6).Value
For i = 1 To UBound(arr, 1) - 1
For j = Len(arr(i, 3)) To 1 Step -1
If Asc(Mid(arr(i, 3), j, 1)) < 0 Then
arr(i, 4) = left(arr(i, 3), j)
arr(i, 5) = Mid(arr(i, 3), j + 1)
If dic.exists(arr(i, 5)) Then
arr(i, 6) = dic(arr(i, 5))
Else
If IsNumeric(arr(i, 5)) Then
arr(i, 6) = Val(arr(i, 5))
Else
arr(i, 6) = arr(i, 5)
End If
End If
Exit For
End If
Next
Next
For i = 1 To UBound(arr, 1) - 1
If arr(i, 1) <> arr(i + 1, 1) Then
For j = p + 1 To i
If arr(j, 4) <> arr(j + 1, 4) Or j = i Then
Call bsort(arr, p + 1, j, 1, UBound(arr, 2), 6)
p = j
End If
Next
p = i
End If
Next
[a2].Resize(UBound(arr, 1) - 1, 3) = arr
End Sub
Function bsort(arr, first, last, left, right, key)
Dim i, j, k, t
For i = first To last - 1
For j = first To last + first - 1 - i
If arr(j, key) > arr(j + 1, key) Then
For k = left To right
t = arr(j, k): arr(j, k) = arr(j + 1, k): arr(j + 1, k) = t
Next
End If
Next
Next
End Function |