|
![](https://clubstatic.excelhome.net/image/common/ico_lz.png)
楼主 |
发表于 2017-2-14 15:37
|
显示全部楼层
Sub 苏宁系统数量和金额匹配_以原始数据为基础()
If MsgBox("请选择苏宁系统各门店当期销售金额汇总工作簿," _
& "确保该簿中有《合并结果》表!", vbYesNo + vbQuestion + vbDefaultButton1) = vbYes Then
GoTo 100
Else
Exit Sub
End If
100:
strfind = Application.InputBox("请输入当期销售报表的起始日期:", Type:=1)
Dim d As Object, sh As Worksheet
Dim arr, brr, crr(), wb As Workbook
Dim x&, y&, z&, k&
Dim i&, j&
Dim dStandard As Object
Dim arrStandard, xstd&, kFinal As Variant, sFinal As String
Dim dFinal As Object, xFinal&
Dim arrFinal As Variant, n&, kk&, splFinal As Variant
Application.ScreenUpdating = False
Set d = CreateObject("scripting.dictionary")
Set dnow = CreateObject("scripting.dictionary")
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
If .Show Then p = .SelectedItems(1) Else: Exit Sub
End With
With GetObject(p)
arr = .Sheets("合并结果").Range("a1").CurrentRegion
.Close False
For x = 2 To UBound(arr)
If arr(x, 13) > strfind Then
If arr(x, 10) = "9019" Or arr(x, 10) = "8417" Then
sell = arr(x, 10) & "+" & arr(x, 13) & "+" & arr(x, 16) '门店代码+销售时间+商品名称
d(sell) = d(sell) + arr(x, 18)
End If
End If
Next
End With
'sj门店代码 9019
'sm门店代码 8417
Set wb = ActiveWorkbook
With wb
brr = .Sheets("合并结果").Range("a1").CurrentRegion
Application.DisplayAlerts = False
For Each sh In .Sheets
If sh.Name = "提取结果" Then sh.Delete
Next
Application.DisplayAlerts = True
For y = 2 To UBound(brr)
If brr(y, 3) = "9019" Or brr(y, 3) = "8417" Then
nowsell = brr(y, 3) & "+" & brr(y, 1) & "+" & brr(y, 7) '门店代码+销售时间+商品名称
dnow(nowsell) = dnow(nowsell) + brr(y, 9)
End If
Next y
anow = dnow.keys
bnow = dnow.items
ReDim crr(1 To UBound(anow) + 1, 1 To 3)
For z = 0 To UBound(anow)
k = k + 1
crr(k, 1) = anow(z)
crr(k, 2) = bnow(z)
Next z
For i = 1 To UBound(crr)
If d.exists(crr(i, 1)) Then
crr(i, 3) = d(crr(i, 1))
End If
Next i
ReDim Preserve crr(1 To UBound(crr), 1 To UBound(crr) + 4)
'==============型号标准数据=================
Set dStandard = CreateObject("scripting.dictionary")
With GetObject("C:\Users\Administrator\AppData\Roaming\Microsoft\AddIns" & "\单品名称和型号标准数据表.xlsx")
arrStandard = .Sheets("苏宁系统结算平台型号整理-字典法").[a1].CurrentRegion
.Close False
End With
For xstd = 2 To UBound(arrStandard)
If Not dStandard.exists(arrStandard(xstd, 1)) Then
dStandard(arrStandard(xstd, 1)) = arrStandard(xstd, 2)
End If
Next
'==============型号标准数据=================
For j = 1 To UBound(crr)
spl = Split(crr(j, 1), "+")
crr(j, 4) = spl(0)
crr(j, 5) = spl(1)
crr(j, 6) = spl(2)
If dStandard.exists(crr(j, 6)) Then
crr(j, 7) = dStandard(crr(j, 6))
End If
Next j
'============对提取的金额和数量分类汇总=====================
Set dFinal = CreateObject("scripting.dictionary")
For xFinal = 1 To UBound(crr)
sFinal = crr(xFinal, 4) & "+" & crr(xFinal, 7)
If Not dFinal.exists(sFinal) Then
dFinal(sFinal) = Array(crr(xFinal, 2), crr(xFinal, 3))
Else
kFinal = dFinal(sFinal)
kFinal(0) = kFinal(0) + crr(xFinal, 2)
kFinal(1) = kFinal(1) + crr(xFinal, 3)
dFinal(sFinal) = kFinal
End If
Next
afinal = dFinal.keys
bfinal = dFinal.items
ReDim arrFinal(1 To UBound(afinal) + 1, 1 To 4)
For n = 0 To UBound(afinal)
kk = kk + 1
splFinal = Split(afinal(n), "+")
arrFinal(kk, 1) = splFinal(0)
arrFinal(kk, 2) = splFinal(1)
arrFinal(kk, 3) = bfinal(n)(0)
arrFinal(kk, 4) = bfinal(n)(1)
Next
'============对提取的金额和数量分类汇总=====================
.Sheets.Add(after:=Sheets(Sheets.Count)).Name = "提取结果"
With .Sheets("提取结果")
.[a1].Resize(1, 4) = Array("门店代码", "商品名称", "数量", "金额")
.[a2].Resize(UBound(arrFinal), UBound(arrFinal, 2)) = arrFinal
.Range("a:g").EntireColumn.AutoFit
End With
End With
Application.ScreenUpdating = True
End Sub
|
|