|
- Sub 库存统计()
- '
- Application.ScreenUpdating = False
- Dim TiArr(), fArr(), xArr(), oArr(), mArr(), yArr()
- Dim fRDic, fCDic, xDic, fNa$, fDR&, mDR&, mDC%, TiC%, ii&, i%
-
- Set fRDic = CreateObject("Scripting.Dictionary")
- Set fCDic = CreateObject("Scripting.Dictionary")
- Set xDic = CreateObject("Scripting.Dictionary")
- TiArr = Array(" ", "每周的销量", "可卖幾天", "可能会退货", "可能会缺货")
-
- With ActiveWorkbook
- fArr = .Sheets("数据").UsedRange.Value
- xArr = .Sheets("过期").UsedRange.Value
- oArr = .Sheets("销量").Range("A1:A3").Value
- End With
- oArr(3, 1) = oArr(2, 1) - oArr(1, 1)
- For i = 1 To UBound(xArr, 1): xDic(xArr(i, 1)) = xArr(i, 3): Next
- fDR = UBound(fArr, 1): mDR = 1: mDC = 2
- ReDim mArr(1 To fDR, 1 To mDC), yArr(1 To fDR, 1 To mDC)
-
- For i = 1 To 2: mArr(mDR, i) = fArr(1, i + 1): yArr(mDR, i) = fArr(1, i + 1): Next
- For ii = 2 To fDR
- If fArr(ii, 1) > oArr(3, 1) And fArr(ii, 1) <= oArr(2, 1) Then
- If fCDic(fArr(ii, 1)) = "" Then
- mDC = mDC + 1
- ReDim Preserve mArr(1 To fDR, 1 To mDC), yArr(1 To fDR, 1 To mDC)
- mArr(1, mDC) = fArr(ii, 1)
- yArr(1, mDC) = fArr(ii, 1)
- fCDic(fArr(ii, 1)) = mDC
- End If
- fNa = fArr(ii, 2) & fArr(ii, 3)
- If fRDic(fNa) = "" Then
- mDR = mDR + 1
- For i = 1 To 2
- mArr(mDR, i) = fArr(ii, i + 1)
- yArr(mDR, i) = fArr(ii, i + 1)
- Next
- fRDic(fNa) = mDR
- End If
- mArr(fRDic(fNa), fCDic(fArr(ii, 1))) = fArr(ii, 5)
- yArr(fRDic(fNa), fCDic(fArr(ii, 1))) = fArr(ii, 4)
- End If
- Next
-
- TiC = UBound(TiArr) + 1
- ReDim Preserve mArr(1 To fDR, 1 To mDC + TiC), yArr(1 To fDR, 1 To mDC + TiC)
- For i = 1 To TiC: mArr(1, mDC + i) = TiArr(i - 1): yArr(1, mDC + i) = TiArr(i - 1): Next
- For ii = 2 To mDR
- For i = 3 To mDC
- If yArr(1, i) > oArr(3, 1) And yArr(1, i) <= oArr(2, 1) Then
- yArr(ii, mDC + 2) = yArr(ii, mDC + 2) + yArr(ii, i)
- End If
- Next
- mArr(ii, mDC + 2) = yArr(ii, mDC + 2)
- If mArr(ii, mDC + 2) <> 0 Then
- mArr(ii, mDC + 3) = mArr(ii, fCDic(oArr(2, 1))) / (mArr(ii, mDC + 2) / oArr(1, 1))
- Else
- mArr(ii, mDC + 3) = "没卖出"
- End If
- If mArr(ii, mDC + 3) >= xDic(mArr(ii, 2)) Then
- mArr(ii, mDC + 4) = "True"
- Else
- mArr(ii, mDC + 4) = "False"
- End If
- If mArr(ii, fCDic(oArr(2, 1))) < 3 Then
- mArr(ii, mDC + 5) = "True"
- Else
- mArr(ii, mDC + 5) = "False"
- End If
- For i = 3 To TiC: yArr(ii, mDC + i) = mArr(ii, mDC + i): Next
- Next
- mDC = mDC + TiC
-
- With ActiveWorkbook.Sheets("销量")
- .Cells.Clear
- .Range("A1:A2").Value = oArr
- .Range("A1").NumberFormatLocal = "0天"
- With .Range("A3").Resize(mDR, mDC)
- .Value = mArr
- .Columns(mDC - 2).NumberFormatLocal = "0天"
- .AutoFilter
- End With
- With .Columns(1).Resize(ColumnSize:=mDC)
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlBottom
- .EntireColumn.AutoFit
- End With
- End With
- Application.ScreenUpdating = True
- MsgBox "完成汇总 " & oArr(2, 1) & " 的数据!"
- '
- End Sub
复制代码
|
|