本帖最后由 张雄友 于 2014-8-5 22:08 编辑
xdragon 发表于 2014-8-5 21:58
红色代码是什么意思?
Sub 去重复提取价格并从小到大排列()
Dim arr, d As Object, brr(), irow&, icol%, product, price, tt#
tt = Timer
arr = Range("B2:L" & Cells(Rows.Count, 2).End(xlUp).Row).Value
Set d = CreateObject("scripting.dictionary")
For irow = 1 To UBound(arr)
If Not d.exists(arr(irow, 1)) Then Set d(arr(irow, 1)) = CreateObject("scripting.dictionary")
For icol = 2 To UBound(arr, 2)
If Len(arr(irow, icol)) > 0 Then d(arr(irow, 1))(arr(irow, icol)) = ""
Next
Next
product = d.keys
ReDim brr(1 To d.Count, 1 To 1)
For irow = 0 To UBound(product)
brr(irow + 1, 1) = product(irow)
price = d(product(irow)).keys
If UBound(price) + 2 > UBound(brr, 2) Then ReDim Preserve brr(1 To UBound(brr), 1 To UBound(price) + 2)
sortnum price
For icol = 0 To UBound(price)
brr(irow + 1, icol + 2) = price(icol)
Next
Next
Range("N10").Resize(UBound(brr), UBound(brr, 2)) = brr
MsgBox "用时" & Format(Timer - tt, "0.00") & "秒"
End Sub
Sub sortnum(n)
Dim i&, j&, t
For i = 0 To UBound(n) - 1
For j = i + 1 To UBound(n)
If n(i) > n(j) Then
t = n(i)
n(i) = n(j)
n(j) = t
End If
Next
Next
End Sub
|