populate summary sheet by merge amounts based on two columns(ID,CUSTOMER)

Abdo

Board Regular
Joined
May 16, 2022
Messages
228
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hi
I need to create summary for report in SUMMARY sheet
ABDD1.xlsm
ABCDEFGH
1
2FROM DATETO DATE
3
4
5
6ITEMCUSTOMERIDOPENINGBUSEBU TOTALSE TOTAL
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Summary



the data in sheets


ABDD1.xlsm
ABCDEF
1ITEMCUSTOMERIDQTY PRICETOTAL
21ABBD1CLOTH-10030.00480.0014,400.00
32SAD1CLOTH-10150.00490.0024,500.00
43SAD2CLOTH-10240.00990.0039,600.00
54SAD3CLOTH-10360.001,100.0066,000.00
65SAD4CLOTH-10480.001,770.00141,600.00
76SERW-00CLOTH-105100.001,680.00168,000.00
87SERW-01CLOTH-106120.001,690.00202,800.00
98SERW-02CLOTH-107140.00580.0081,200.00
109SERW-03CLOTH-108160.001,660.00265,600.00
1110SERW-04CLOTH-109180.001,700.00306,000.00
1211SERW-05CLOTH-110200.001,600.00320,000.00
1312SERW-06CLOTH-111201.001,780.00357,780.00
1413ABBD1CLOTH-10160.00480.0028,800.00
1514SAD2CLOTH-10410.001,790.0017,900.00
1615SAD1CLOTH-10890.001,620.00145,800.00
OPENING
Cell Formulas
RangeFormula
F2:F16F2=D2*E2




ABDD1.xlsm
ABCDEFG
1ITEMCUSTOMERDATEIDQTY PRICETOTAL
21ABBD115/01/2024CLOTH-10022.00500.0011,000.00
32ABBD115/01/2024CLOTH-10125.00525.0013,125.00
43SAD115/01/2024CLOTH-10260.00920.0055,200.00
54SAD218/01/2024CLOTH-10350.001,000.0050,000.00
65SAD318/01/2024CLOTH-104110.001,800.00198,000.00
76SAD418/01/2024CLOTH-105140.001,800.00252,000.00
87ABBD121/01/2024CLOTH-10150.001,800.0090,000.00
98ABBD122/01/2024CLOTH-10760.00450.0027,000.00
109SAD123/01/2024CLOTH-10888.001,650.00145,200.00
1110SAD223/01/2024CLOTH-10990.001,660.00149,400.00
1211SERW-0023/01/2024CLOTH-110200.001,550.00310,000.00
1312SERW-0123/01/2024CLOTH-101120.00420.0050,400.00
1413SERW-0023/01/2024CLOTH-101120.00430.0051,600.00
1514SAD228/01/2024CLOTH-10910.001,670.0016,700.00
1615SAD129/01/2024CLOTH-108100.001,650.00165,000.00
1716SERW-0730/01/2024CLOTH-112120.001,640.00196,800.00
1817SERW-0831/01/2024CLOTH-113100.001,625.00162,500.00
1918SERW-0831/01/2024CLOTH-11320.001,625.0032,500.00
BU
Cell Formulas
RangeFormula
G2:G19G2=E2*F2




ABDD1.xlsm
ABCDEFG
1ITEMCUSTOMERDATEIDQTY PRICETOTAL
21SERW-0015/01/2024CLOTH-11010.001,600.0016,000.00
32SERW-0115/01/2024CLOTH-10120.00500.0010,000.00
43SERW-0015/01/2024CLOTH-10125.00480.0012,000.00
54SERW-0015/01/2024CLOTH-110200.001,550.00310,000.00
65SAD318/01/2024CLOTH-10410.001,890.0018,900.00
76SAD319/01/2024CLOTH-10410.001,880.0018,800.00
87ABBD120/01/2024CLOTH-1065.001,900.009,500.00
98ABBD121/01/2024CLOTH-1075.00500.002,500.00
109SAD421/01/2024CLOTH-10550.001,995.0099,750.00
1110SAD321/01/2024CLOTH-1045.001,880.009,400.00
1211ABBD122/01/2024CLOTH-10610.001,990.0019,900.00
1312ABBD122/01/2024CLOTH-1015.001,890.009,450.00
1413SAD322/01/2024CLOTH-10410.001,860.0018,600.00
SE
Cell Formulas
RangeFormula
G2:G14G2=E2*F2



if the B3,C3 don't contain dates then the report in summary sheet will be




ABDD1.xlsm
ABCDEFGHI
1
2FROM DATETO DATE
3
4
5
6ITEMCUSTOMERIDOPENINGBUSEOPENING TOTALBU TOTALSE TOTAL
71ABBD1CLOTH-10030.0022.0014,400.0011,000.00
82ABBD1CLOTH-10160.0075.005.0028,800.00103,125.009,450.00
93ABBD1CLOTH-10615.0029,400.00
104ABBD1CLOTH-10760.005.0027,000.002,500.00
115SAD1CLOTH-10150.0024,500.00
126SAD1CLOTH-10890.00188.00145,800.00310,200.00
137SAD1CLOTH-10260.0055,200.00
148SAD2CLOTH-10240.0039,600.00
159SAD2CLOTH-10350.0050,000.00
1610SAD2CLOTH-10410.0017,900.00
1711SAD2CLOTH-109100.00166,100.00
1812SAD3CLOTH-10360.0066,000.00
1913SAD3CLOTH-104110.0035.00198,000.0065,700.00
2014SAD4CLOTH-10480.00141,600.00
2115SAD4CLOTH-105140.0050.00252,000.0099,750.00
2216SERW-00CLOTH-101120.0025.0051,600.0012,000.00
2317SERW-00CLOTH-105100.00168,000.00
2418SERW-00CLOTH-110200.00210.00310,000.00326,000.00
2519SERW-01CLOTH-101120.0020.0050,400.0010,000.00
2620SERW-01CLOTH-106120.00202,800.00
2721SERW-02CLOTH-107140.0081,200.00
2822SERW-03CLOTH-108160.00265,600.00
2923SERW-04CLOTH-109180.00306,000.00
3024SERW-05CLOTH-110200.00320,000.00
3125SERW-06CLOTH-111201.00357,780.00
3226SERW-07CLOTH-112120.00196,800.00
3327SERW-08CLOTH-113120.00195,000.00
Summary

will be brings all of customers , ID across sheets as in column B:C in summary sheet
will brings QTY and TOTAL from OPENING sheet as in column D,G
will merge duplicates based on two columns (CUSTOMER,ID) so will merge QTY,TOTAL columns for BU sheet and put in columns E,H in summary sheet
will merge duplicates based on two columns (CUSTOMER,ID) so will merge QTY,TOTAL columns for SE sheet and put in columns F,I in summary sheet


if the B3,C3 contain dates then will match with column C for BU,SE sheets the report in summary sheet will be
ABDD1.xlsm
ABCDEFGHI
1
2FROM DATETO DATE
315/01/202421/01/2024
4
5
6ITEMCUSTOMERIDOPENINGBUSEOPENING TOTALBU TOTALSE TOTAL
71ABBD1CLOTH-10030.0022.0014,400.0011,000.00
82ABBD1CLOTH-10160.0075.0028,800.00103,125.00
93ABBD1CLOTH-1065.009,500.00
104ABBD1CLOTH-1075.002,500.00
115SAD1CLOTH-10150.0024,500.00
126SAD1CLOTH-10890.00145,800.00
137SAD1CLOTH-10260.00
148SAD2CLOTH-10240.0039,600.00
159SAD2CLOTH-10350.0050,000.00
1610SAD2CLOTH-10410.0017,900.00
1711SAD2CLOTH-109
1812SAD3CLOTH-10360.0066,000.00
1913SAD3CLOTH-104110.0025.00198,000.0047,100.00
2014SAD4CLOTH-10480.00141,600.00
2115SAD4CLOTH-105140.0050.00252,000.0099,750.00
2216SERW-00CLOTH-10125.0012,000.00
2317SERW-00CLOTH-105100.00168,000.00
2418SERW-00CLOTH-110210.00326,000.00
2519SERW-01CLOTH-10120.0010,000.00
2620SERW-01CLOTH-106120.00202,800.00
2721SERW-02CLOTH-107140.0081,200.00
2822SERW-03CLOTH-108160.00265,600.00
2923SERW-04CLOTH-109180.00306,000.00
3024SERW-05CLOTH-110200.00320,000.00
3125SERW-06CLOTH-111201.00357,780.00
Summary

as you see will brings QTY,TOTAL from opening sheet even search by two dates.
I hope some body help me towrite macro to deal with big data for each sheet .
 
Last edited:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try:

VBA Code:
Sub populate_summary()
  Dim sh1 As Worksheet
  Dim dic As Object, ky As Variant
  Dim a As Variant, b As Variant, c As Variant, d As Variant
  Dim i%, y%, nRow%
  Dim dt1 As Long, dt2 As Long, ini As Long, fin As Long
  
  Set sh1 = Sheets("Summary")
  Set dic = CreateObject("Scripting.Dictionary")
  dt1 = sh1.Range("B3").Value
  dt2 = sh1.Range("C3").Value
  
  a = Sheets("OPENING").Range("A2", Sheets("OPENING").Range("F" & Rows.Count).End(3)).Value2
  b = Sheets("BU").Range("A2", Sheets("BU").Range("G" & Rows.Count).End(3)).Value2
  c = Sheets("SE").Range("A2", Sheets("SE").Range("G" & Rows.Count).End(3)).Value2
  
  ReDim d(1 To UBound(a, 1) + UBound(b, 1) + UBound(c, 1), 1 To 9)
  
  'OPENING
  For i = 1 To UBound(a, 1)
    ky = a(i, 2) & "|" & a(i, 3)
    If Not dic.exists(ky) Then dic(ky) = dic.Count + 1
    nRow = dic(ky)
    d(nRow, 2) = a(i, 2)
    d(nRow, 3) = a(i, 3)
    d(nRow, 4) = d(nRow, 4) + a(i, 4)
    d(nRow, 7) = d(nRow, 7) + a(i, 6)
  Next
  
  'BU
  For i = 1 To UBound(b, 1)
    If dt1 = 0 Then ini = b(i, 3) Else ini = dt1
    If dt2 = 0 Then fin = b(i, 3) Else fin = dt2
    If b(i, 3) >= ini And b(i, 3) <= fin Then
      ky = b(i, 2) & "|" & b(i, 4)
      If Not dic.exists(ky) Then dic(ky) = dic.Count + 1
      nRow = dic(ky)
      d(nRow, 2) = b(i, 2)
      d(nRow, 3) = b(i, 4)
      d(nRow, 5) = d(nRow, 5) + b(i, 5)
      d(nRow, 8) = d(nRow, 8) + b(i, 7)
    End If
  Next
  
  'SE
  For i = 1 To UBound(c, 1)
    If dt1 = 0 Then ini = c(i, 3) Else ini = dt1
    If dt2 = 0 Then fin = c(i, 3) Else fin = dt2
    If c(i, 3) >= ini And c(i, 3) <= fin Then
      ky = c(i, 2) & "|" & c(i, 4)
      If Not dic.exists(ky) Then dic(ky) = dic.Count + 1
      nRow = dic(ky)
      d(nRow, 2) = c(i, 2)
      d(nRow, 3) = c(i, 4)
      d(nRow, 6) = d(nRow, 6) + c(i, 5)
      d(nRow, 9) = d(nRow, 9) + c(i, 7)
    End If
  Next
  
  Application.ScreenUpdating = False
  With sh1.Range("A7:I" & Rows.Count)
    .ClearContents
    .HorizontalAlignment = xlCenter
  End With
  sh1.Range("D7:I" & Rows.Count).NumberFormat = "#,##0.00"
  With sh1.Range("A7").Resize(UBound(d, 1), UBound(d, 2))
    .Value = d
    .Sort sh1.Range("B6"), xlAscending, sh1.Range("C6"), Header:=xlYes
  End With
  With sh1.Range("A7")
    .Value = 1
    .AutoFill Destination:=sh1.Range("A7:A" & sh1.Range("B" & Rows.Count).End(3).Row), Type:=xlFillSeries
  End With
  
  Application.ScreenUpdating = True
End Sub


😇
 
Upvote 0
Solution
wow !
this is really fast and great!(y)
I've found some errors when brings the numbers for some ID in my OP when I tested your code , sorry about it :eek:
many thanks for the code.;)
 
Upvote 0
I've found some errors when brings the numbers for some ID in my OP when I tested your code , sorry about it
Yes I noticed that. But your examples are quite good, I even take them as a model for other users to present their examples like yours.
😁
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,104
Members
453,021
Latest member
Justyna P

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