|
本帖最后由 jsgj2023 于 2018-9-18 17:15 编辑
- Public dic As Object, strResult
- Sub Adele()
- Dim arr, i&, jSum&, x&
- Dim rStart&, tempS
- With Sheets("软件产品列表")
- brr = .Range("a1").CurrentRegion
- Set dic = CreateObject("scripting.dictionary")
- For x = 2 To UBound(brr)
- dic(brr(x, 1)) = brr(x, 5)
- Next
- End With
-
- With Sheets("YB063170571,773")
- i = 1: tempI = 1: rStart = 3
- arr = .Range("a1:n" & .Cells(Rows.Count, 1).End(xlUp).Row)
- For x = 3 To UBound(arr)
- jSum = jSum + arr(x, 10)
- If jSum < 115900 Then
- arr(x, 14) = i
- Else
- tempX = x
- tempS = GetRemarks(arr, tempI, tempX)
- arr(rStart, 13) = Mid(GetDistinct(tempS), 2)
- rStart = tempX
- tempI = tempX
- i = i + 1
- arr(x, 14) = i
- jSum = 0
- jSum = arr(x, 10)
- End If
- Next
- Range("a1").Resize(UBound(arr), UBound(arr, 2)) = arr
- End With
- End Sub
- Function GetRemarks(a, iStart, xEnd)
- For y = iStart To xEnd - 1
- If dic.exists(a(y, 3)) Then s = s & "," & dic(a(y, 3))
- Next
- GetRemarks = s
- End Function
- Function GetDistinct(disStr)
- Dim dicDis As Object
- arrsplit = Split(Mid(disStr, 2), ",")
- Set dicDis = CreateObject("scripting.dictionary")
- For x = 0 To UBound(arrsplit)
- dicDis(arrsplit(x)) = ""
- Next
- dkey = dicDis.keys
- For y = 0 To dicDis.Count - 1
- If Len(dkey(y)) Then strResult = strResult & "," & dkey(y)
- Next
- GetDistinct = strResult
- dicDis.RemoveAll
- strResult = ""
- End Function
复制代码
|
|