|
- Sub qs()
- Application.ScreenUpdating = False
- Dim arr, i, dic
- Set dic = CreateObject("scripting.dictionary")
- arr = Sheet1.UsedRange.Value
- m = 1: n = 4
- ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2))
- brr(1, 1) = "序号": brr(1, 2) = "物料编码": brr(1, 3) = "库存数量)"
- ReDim crr(1 To UBound(arr), 1 To 1)
- For i = 2 To UBound(arr)
- For j = 5 To UBound(arr, 2)
- If IsDate(arr(1, j)) And arr(1, j) <> "" Then '时间
- dt = CDate(arr(1, j))
- s = arr(i, 1) & "|" & arr(1, j)
-
- If Not dic.exists(s) Then
- dic(s) = arr(i, j)
- Else
- dic(s) = dic(s) + arr(i, j)
- End If
- If Not dic.exists(dt) Then
- n = n + 1
- brr(1, n) = arr(1, j)
- dic(dt) = n
- End If
- End If
- Next
- bm = arr(i, 1)
- If bm <> Empty Then
- If Not dic.exists(bm) Then '物料编码
- m = m + 1
- brr(m, 1) = bm
- dic(bm) = m
- crr(m, 1) = m
- End If
- End If
- Next
- For ii = 2 To m
- For jj = 5 To n
- s = brr(ii, 1) & "|" & brr(1, jj)
- brr(ii, jj) = dic(s)
- Next
- Next
- With Sheet3
- .Range("a3").Resize(50000, 300).ClearContents
- .Range("b3").Resize(m, n) = brr
- .Range("a3").Resize(m, 1) = crr
- .ListObjects.Add xlSrcRange, .Range("a3").Resize(m, n + 1), , xlYes
- End With
- Set dic = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|