|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
‘当时没有D、E这2列,稍作修改,先测试一下,,,
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(, 8).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, 6) = left(arr(i, 3), j)
arr(i, 7) = Mid(arr(i, 3), j + 1)
If dic.exists(arr(i, 7)) Then
arr(i, 8) = dic(arr(i, 7))
Else
If IsNumeric(arr(i, 7)) Then
arr(i, 8) = Val(arr(i, 7))
Else
arr(i, 8) = arr(i, 7)
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, 6) <> arr(j + 1, 6) Or j = i Then
Call bsort(arr, p + 1, j, 1, UBound(arr, 2), 8)
p = j
End If
Next
p = i
End If
Next
[a2].Resize(UBound(arr, 1) - 1, 5) = 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 |
评分
-
1
查看全部评分
-
|