SUMIF VBA ARRAY & DICTIONARY

roykana

Active Member
Joined
Mar 8, 2018
Messages
311
Office Version
  1. 2010
Platform
  1. Windows
Dear all master,
I want a fast code sumif vba array and dictionary because there are three hundred thousand records. I've also made the sumif vba array and dictionary code but it only works for 1 column and 1 criteria results.
Please help for the solution.
sheet name "OPS" with table name "OPS" with blue marking in the desired result in sheet "RECON"

SUMIF VBA ARRAY & DICTIONARY.xlsm
ABCDEF
1ITEM NOBOJCJRM18M07MD2
201-173800983610152
301-17380171610654
401-173801851210751
501-173801861011121314
66441262821
OPS
Cell Formulas
RangeFormula
B6B6=SUBTOTAL(109,[BOJ])
C6C6=SUBTOTAL(109,[CJR])
D6D6=SUBTOTAL(109,[M18])
E6E6=SUBTOTAL(109,[M07])
F6F6=SUBTOTAL(109,[MD2])


sheet name "DBALL" with table name "DBALL" with yellow marking in the desired result in sheet "RECON"

SUMIF VBA ARRAY & DICTIONARY.xlsm
ABCDEFGHIJKLMNOPQRSTU
1PNMITMITCQTYUNICIUNODDPRNCURQABGLBDPTDTSCIAUNBDATESACDEPTTRANSGROUPITEM NO
2GPPI11801001TEST S 20525 DIGITALITYT2052536Pcs8900001002/01/2018A.01.01.001.063BOJPURCHASEIn01-17380098
3GPPI11801002TEST S 20551 DELIOT2055160Pcs8900001002/01/2018A.01.01.001.063M18PURCHASEIn01-17380171
4GPPI11801003TEST S 20526 DIGITALITYT2052636Pcs8900001002/01/2018A.01.01.001.063M07PURCHASEIn01-17380185
5GPPI11801004TEST S 20552 DELIOT2055260Pcs8900001002/01/2018A.01.01.001.063MD2PURCHASEIn01-17380186
6GPPI11801005TEST S 20525 DIGITALITYT2052536Pcs8900001002/01/2018A.01.01.001.063BOJSALES01-17380098
7GPPI11801006TEST S 20551 DELIOT2055160Pcs8900001002/01/2018A.01.01.001.063M18SALES01-17380171
8GPPI11801007TEST S 20526 DIGITALITYT2052636Pcs8900001002/01/2018A.01.01.001.063M07SALES01-17380185
9GPPI11801008TEST S 20552 DELIOT2055260Pcs8900001002/01/2018A.01.01.001.063MD2SALES01-17380186
10GPPI11801009TEST S 20525 DIGITALITYT2052536Pcs8900001002/01/2018A.01.01.001.063BOJRET PURCH01-17380098
11GPPI11801010TEST S 20551 DELIOT2055160Pcs8900001002/01/2018A.01.01.001.063M18RET PURCH01-17380171
12GPPI11801011TEST S 20526 DIGITALITYT2052636Pcs8900001002/01/2018A.01.01.001.063M07RET PURCH01-17380185
13GPPI11801012TEST S 20552 DELIOT2055260Pcs8900001002/01/2018A.01.01.001.063MD2RET PURCH01-17380186
14GPPI11801013TEST S 20525 DIGITALITYT2052536Pcs8900001002/01/2018A.01.01.001.063BOJRET SALES01-17380098
15GPPI11801014TEST S 20551 DELIOT2055160Pcs8900001002/01/2018A.01.01.001.063M18RET SALES01-17380171
16GPPI11801015TEST S 20526 DIGITALITYT2052636Pcs8900001002/01/2018A.01.01.001.063M07RET SALES01-17380185
17GPPI11801016TEST S 20552 DELIOT2055260Pcs8900001002/01/2018A.01.01.001.063MD2RET SALES01-17380186
DBALL


sheet name "IFGALL" with table name "IFGALL" with red marking in the desired result in sheet "RECON"

SUMIF VBA ARRAY & DICTIONARY.xlsm
ABCDE
1ITMITCQOHGROUP DEPTITEM NO
2TEST S 20525 DIGITALITYT2052536BOJ01-17380098
3TEST S 20551 DELIOT2055136BOJ01-17380171
4TEST S 20526 DIGITALITYT2052636BOJ01-17380185
5TEST S 20552 DELIOT2055236BOJ01-17380186
6TEST S 20525 DIGITALITYT2052510CJR01-17380098
7TEST S 20551 DELIOT2055110CJR01-17380171
8TEST S 20526 DIGITALITYT2052610CJR01-17380185
9TEST S 20552 DELIOT2055211CJR01-17380186
10TEST S 20525 DIGITALITYT205251M1801-17380098
11TEST S 20551 DELIOT205511M1801-17380171
12TEST S 20526 DIGITALITYT205261M1801-17380185
13TEST S 20552 DELIOT205522M1801-17380186
14TEST S 20525 DIGITALITYT205255M0701-17380098
15TEST S 20551 DELIOT205515M0701-17380171
16TEST S 20526 DIGITALITYT205265M0701-17380185
17TEST S 20552 DELIOT205525M0701-17380186
18TEST S 20525 DIGITALITYT205252MD201-17380098
19TEST S 20551 DELIOT205512MD201-17380171
20TEST S 20526 DIGITALITYT205262MD201-17380185
21TEST S 20552 DELIOT205522MD201-17380186
IFGALL



desired result
SUMIF VBA ARRAY & DICTIONARY.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAO
1OPSPURCHASESALESRET SALESRET PURCHIFGALLCALCULATIONCHECK
2ITEM NOBOJCJRM18M07MD2BOJCJRM18M07MD2BOJCJRM18M07MD2BOJCJRM18M07MD2BOJCJRM18M07MD2BOJCJRM18M07MD2BOJCJRM18M07MD2BOJCJRM18M07MD2
301-17380098361015236000036000036000036000036101523610152sssss
401-1738017161065400600000600000600000600036101523610152sssss
501-17380185121075100036000036000036000036036101523610152sssss
601-17380186101112131400006000006000006000006036112523610152snsnsss
7TOTAL6441262821360603660360603660360603660360603660144415208144404208snsnsss
RECON
Cell Formulas
RangeFormula
B3:B6B3=SUMIF(OPS[ITEM NO],$A3,OPS[BOJ])
C3:C6C3=SUMIF(OPS[ITEM NO],$A3,OPS[CJR])
D3:D6D3=SUMIF(OPS[ITEM NO],$A3,OPS[M18])
E3:E6E3=SUMIF(OPS[ITEM NO],$A3,OPS[M07])
F3:F6F3=SUMIF(OPS[ITEM NO],$A3,OPS[MD2])
G3:K6G3=SUMIFS(DBALL[QTY],DBALL[ITEM NO],RECON!$A3,DBALL[DEPT],RECON!G$2,DBALL[TRANS],RECON!$G$1)
L3:P6L3=SUMIFS(DBALL[QTY],DBALL[ITEM NO],RECON!$A3,DBALL[DEPT],RECON!L$2,DBALL[TRANS],RECON!$L$1)
Q3:U6Q3=SUMIFS(DBALL[QTY],DBALL[ITEM NO],RECON!$A3,DBALL[DEPT],RECON!Q$2,DBALL[TRANS],RECON!$Q$1)
V3:Z6V3=SUMIFS(DBALL[QTY],DBALL[ITEM NO],RECON!$A3,DBALL[DEPT],RECON!V$2,DBALL[TRANS],RECON!$V$1)
AA3:AE6AA3=SUMIFS(IFGALL[QOH],IFGALL[ITEM NO],RECON!$A3,IFGALL[GROUP DEPT],RECON!AA$2)
AF3:AJ6AF3=(B$3+G$3+Q$3)-(L$3+V$3)
AK3:AO7AK3=IF(AA3=AF3,"s","ns")
B7:AJ7B7=SUM(B3:B6)


VBA Code:
Sub sumifarraydictionary()

   Dim Ary As Variant, Tmp As Variant
   Dim r As Long
   t = Timer
  
   Ary = Sheets("OPS").ListObjects("OPS").DataBodyRange.Value2
   With CreateObject("scripting.dictionary")
      For r = 1 To UBound(Ary)
         If Not .Exists(Ary(r, 1)) Then
            .Add Ary(r, 1), Array(Ary(r, 2), 0, 0)
         Else
            Tmp = .Item(Ary(r, 1))(0) + Ary(r, 2)
            .Item(Ary(r, 1)) = Array(Tmp, 0, 0)
         End If
      Next r
Sheets("RECON").Range("A3").Resize(.Count).Value = Application.Transpose(.Keys)
      Sheets("RECON").Range("B3").Resize(.Count, 1).Value = Application.Index(.items, 0)
   End With
      Debug.Print "It's done in: " & Timer - t & " seconds"
End Sub
 
I thought I gave you the answer in post #18, so I don't understand what you need the code in post #14 is "It's perfectly".
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I thought I gave you the answer in post #18, so I don't understand what you need the code in post #14 is "It's perfectly".
@DanteAmor
Dear Mr. Dante Amor

I'm sorry I mean a different case example because this is just a little problem maybe you can help in this project. But if there are objections or disturbed then I apologize to you.

Thanks
roykana
 
Upvote 0
If they are different cases you must create a new thread. There you expose with examples the data you have and the desired results.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,203
Members
452,617
Latest member
Narendra Babu D

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top