|
本帖最后由 lgzxmlg 于 2023-2-11 11:12 编辑
Private Sub Worksheet_Activate()
Application.DisplayAlerts = False
Rows("4:1048576").ClearContents
Set dic = CreateObject("SCRIPTING.DICTIONARY")
rng = Sheets("货品资料").[A1].CurrentRegion
For r = 2 To UBound(rng)
Y = rng(r, 1)
dic(Y) = rng(r, 2) & "," & rng(r, 3) & "," & rng(r, 4) & "," & rng(r, 5) & "," & rng(r, 6) & "," & rng(r, 9)
Next r
[a4].Resize(dic.Count, 1) = Application.Transpose(dic.KEYS)
[B4].Resize(dic.Count, 1) = Application.Transpose(dic.ITEMS)
[B4].Resize(dic.Count, 1).TextToColumns DataType:=xlDelimited, ConsecutiveDelimiter:=True, COMMA:=True
Set DIC1 = CreateObject("SCRIPTING.DICTIONARY") '数量
Set DIC2 = CreateObject("SCRIPTING.DICTIONARY") '金额
rng = Sheets("入库明细").[A1].CurrentRegion
For r = 2 To UBound(rng)
Y = rng(r, 6)
DIC1(Y) = DIC1(Y) + rng(r, 11)
DIC2(Y) = DIC2(Y) + rng(r, 13)
Next r
'出库明细
Set DIC3 = CreateObject("SCRIPTING.DICTIONARY") '数量
Set DIC4 = CreateObject("SCRIPTING.DICTIONARY") ' 金额
rng = Sheets("出库明细").[A1].CurrentRegion
For r = 2 To UBound(rng)
Y = rng(r, 7)
DIC3(Y) = DIC3(Y) + rng(r, 12)
DIC4(Y) = DIC4(Y) + rng(r, 14)
Next r
TARR = [A1].CurrentRegion
For r = 4 To UBound(TARR)
Y = TARR(r, 1)
TARR(r, 9) = DIC1(Y)
TARR(r, 10) = DIC2(Y)
TARR(r, 11) = DIC3(Y)
TARR(r, 12) = DIC4(Y)
Next r
[A1].CurrentRegion = TARR
[H4].Resize(dic.Count, 1).Formula = "=F4*G4"
[M4].Resize(dic.Count, 1).Formula = "=G4+I4-K4"
[N4].Resize(dic.Count, 1).Formula = "=F4*M4"
[O4].Resize(dic.Count, 1).Formula = "=L4+N4-J4-H4"
[g2].Formula = "=SUBTOTAL(9,G4:G65536)"
[h2].Formula = "=SUBTOTAL(9,H4:H65536)"
[i2].Formula = "=SUBTOTAL(9,I4:I65536)"
[J2].Formula = "=SUBTOTAL(9,J4:J65536)"
[K2].Formula = "=SUBTOTAL(9,K4:K65536)"
[L2].Formula = "=SUBTOTAL(9,L4:L65536)"
[M2].Formula = "=SUBTOTAL(9,M4:M65536)"
[N2].Formula = "=SUBTOTAL(9,N4:N65536)"
[O2].Formula = "=SUBTOTAL(9,O4:O65536)"
Range("a4").Select
Application.DisplayAlerts = True
End Sub
以上代码想加个日期限制。开始日期放在ks = Sheets("库存统计").Range("R1"),结束日期放在js = Sheets("库存统计").Range("T1")。表格中日期都在表格的A列。如何修改代码?请老师帮忙解决。
增加条件.zip
(162.29 KB, 下载次数: 6)
|
|