using sorting and array to deal with big data for expected result

Hasson

Active Member
Joined
Apr 8, 2021
Messages
390
Office Version
  1. 2016
Platform
  1. Windows
Hello
I need to help from experts master to writing smart code to deal with 15000 rows for each sheet .
if cells D2,E2 are empty then will create report from row 5 in expected result
first step will merge QTY for each sheet alone based on two columns together (B,D)
and the headers G:J are matched with sheets names to merge QTY for each sheet alone .
second step will calculate PURCHASE AVERAGE based on average price for just PURCHASE sheet , in column I , will calculate SALES AVERAGE based on average price for just SALES sheet in column I , but when calculate price average should be based on just column B .
and calculation as the formula is existed in BALANCE column.
2222.xlsm
ABCDEFGHIJ
1DATEBBTINV NONAMEcmmddmnnmQTYPRICETOTAL
201/01/2021bfg-hy1invn-as1asz-1cmm-1000ddm-1000nnm-1000200.00$350.00$70,000.00
302/01/2021bfg-hy2invn-as2asz-2cmm-1001ddm-1001nnm-100165.00$600.00$39,000.00
403/01/2021bfg-hy3invn-as3asz-3cmm-1002ddm-1002nnm-100280.00$700.00$56,000.00
504/01/2021bfg-hy4invn-as4asz-4cmm-1003ddm-1003nnm-100354.00$500.00$27,000.00
605/01/2021bfg-hy5invn-as5asz-5cmm-1004ddm-1004nnm-100434.00$400.00$13,600.00
706/01/2021bfg-hy6invn-as6asz-6cmm-1005ddm-1005nnm-100512.00$200.00$2,400.00
807/01/2021bfg-hy1invn-as7asz-1cmm-1000ddm-1000nnm-100045.00$400.00$18,000.00
909/01/2021bfg-hy3invn-as9asz-3cmm-1002ddm-1002nnm-100254.00$900.00$48,600.00
1010/01/2021bfg-hy4invn-as10asz-4cmm-1003ddm-1003nnm-100321.00$800.00$16,800.00
1111/01/2021bfg-hy5invn-as11asz-5cmm-1004ddm-1004nnm-100455.00$670.00$36,850.00
1212/01/2021bfg-hy6invn-as12asz-6cmm-1005ddm-1005nnm-100566.00$431.00$28,446.00
Purchase
Cell Formulas
RangeFormula
J2:J12J2=H2*I2



2222.xlsm
ABCDEFGHIJ
1DATEBBTINV NONAMEcmmddmnnmQTYPRICETOTAL
201/01/2021bfg-hy1invn-as1asz-1cmm-1000ddm-1000nnm-100010.00$400.00$4,000.00
302/01/2021bfg-hy2invn-as2asz-2cmm-1001ddm-1001nnm-10015.00$700.00$3,500.00
403/01/2021bfg-hy3invn-as3asz-3cmm-1002ddm-1002nnm-100220.00$800.00$16,000.00
504/01/2021bfg-hy4invn-as4asz-4cmm-1003ddm-1003nnm-10035.00$800.00$4,000.00
605/01/2021bfg-hy5invn-as5asz-5cmm-1004ddm-1004nnm-10042.00$700.00$1,400.00
706/01/2021bfg-hy6invn-as6asz-6cmm-1005ddm-1005nnm-10051.00$600.00$600.00
807/01/2021bfg-hy1invn-as7asz-1cmm-1000ddm-1000nnm-100010.00$500.00$5,000.00
908/01/2021bfg-hy2invn-as8asz-2cmm-1001ddm-1001nnm-100122.00$700.00$15,400.00
1009/01/2021bfg-hy3invn-as9asz-3cmm-1002ddm-1002nnm-100212.00$1,000.00$12,000.00
1110/01/2021bfg-hy4invn-as10asz-4cmm-1003ddm-1003nnm-100310.00$1,000.00$10,000.00
1211/01/2021bfg-hy5invn-as11asz-5cmm-1004ddm-1004nnm-10044.00$700.00$2,800.00
1312/01/2021bfg-hy6invn-as12asz-6cmm-1005ddm-1005nnm-10052.00$800.00$1,600.00
1412/01/2021bfg-hy6invn-as13asz-7cmm-1005ddm-1005nnm-10052.00$820.00$1,640.00
1513/01/2021bfg-hy1invn-as14asz-8cmm-1000ddm-1000nnm-10002.00$420.00$840.00
Sales
Cell Formulas
RangeFormula
J2:J15J2=H2*I2




2222.xlsm
ABCDEFGHIJ
1DATEBBTINV NONAMEcmmddmnnmQTYPRICETOTAL
201/01/2021bfg-hy1invn-as1asz-1cmm-1000ddm-1000nnm-100010.00$350.00$3,500.00
302/01/2021bfg-hy1invn-as2asz-1cmm-1000ddm-1000nnm-100010.00$400.00$4,000.00
403/01/2021bfg-hy1invn-as3asz-3cmm-1000ddm-1000nnm-100010.00$350.00$3,500.00
504/01/2021bfg-hy2invn-as4asz-4cmm-1001ddm-1001nnm-100115.00$600.00$9,000.00
605/01/2021bfg-hy3invn-as5asz-5cmm-1002ddm-1002nnm-100210.00$700.00$7,000.00
purchase returns
Cell Formulas
RangeFormula
J2:J6J2=H2*I2


2222.xlsm
ABCDEFGHIJ
1DATEBBTINV NONAMEcmmddmnnmQTYPRICETOTAL
201/01/2021bfg-hy1invn-as1asz-1cmm-1000ddm-1000nnm-100010.00$400.00$4,000.00
302/01/2021bfg-hy2invn-as2asz-2cmm-1001ddm-1001nnm-10015.00$700.00$3,500.00
403/01/2021bfg-hy2invn-as3asz-3cmm-1001ddm-1001nnm-10015.00$700.00$3,500.00
504/01/2021bfg-hy1invn-as4asz-1cmm-1000ddm-1000nnm-10005.00$500.00$2,500.00
605/01/2021bfg-hy2invn-as5asz-3cmm-1001ddm-1001nnm-10012.00$700.00$1,400.00
sales returns
Cell Formulas
RangeFormula
J2:J6J2=H2*I2


if D2,E2 are empty
2222.xlsm
ABCDEFGHIJKLM
1FROM DATETO DATE
2
3
4ITEMBBTNAMEcmmddmnnmPurchaseSalespurchase returnssales returnsPURCHASE AVERAGESALE AVERAGEBALANCE
5
6
7
8
expected result



should be
2222.xlsm
ABCDEFGHIJKLM
1FROM DATETO DATE
2
3
4ITEMBBTNAMEcmmddmnnmPurchaseSalespurchase returnssales returnsPURCHASE AVERAGESALE AVERAGEBALANCE
51bfg-hy1asz-1cmm-1000cmm-1000ddm-1000245.0020.0020.0015.00$375.00$440.00$14,300.00
62bfg-hy1asz-3cmm-1000cmm-1000ddm-1000--10.00-$375.00$440.00-$650.00
73bfg-hy1asz-8cmm-1000cmm-1000ddm-1000-2.00--$375.00$440.00-$130.00
84bfg-hy2asz-2cmm-1001cmm-1001ddm-100165.0027.00-5.00$600.00$700.00$4,300.00
95bfg-hy2asz-3cmm-1001cmm-1001ddm-1001---7.00$600.00$700.00$700.00
106bfg-hy2asz-4cmm-1001cmm-1001ddm-1001--15.00-$600.00$700.00-$1,500.00
117bfg-hy3asz-3cmm-1002cmm-1002ddm-1002134.0032.00--$700.00$900.00$20,400.00
128bfg-hy3asz-5cmm-1002ddm-1002nnm-1002-10.00-$700.00$900.00-$2,000.00
139bfg-hy4asz-4cmm-1003cmm-1003ddm-100375.0015.00--$500.00$900.00$24,000.00
1410bfg-hy5asz-5cmm-1004cmm-1004ddm-100489.006.00--$670.00$700.00$2,490.00
1511bfg-hy6asz-6cmm-1005ddm-1005nnm-100578.003.00--$315.50$740.00$31,837.50
1612bfg-hy6asz-7cmm-1005ddm-1005nnm-1005-2.00--$315.50$740.00-$849.00
expected result
Cell Formulas
RangeFormula
M5:M16M5=(G5+J5-I5-H5) *(L5-K5)



if D2,E2 contains dates then should merge within dates like this
2222.xlsm
ABCDEFGHIJKLM
1FROM DATETO DATE
201/01/202104/01/2021
3
4ITEMBBTNAMEcmmddmnnmPurchaseSalespurchase returnssales returnsPURCHASE AVERAGESALE AVERAGEBALANCE
51bfg-hy1asz-1cmm-1000cmm-1000ddm-1000200.0010.0020.0015.00$350.00$400.00$9,250.00
62bfg-hy1asz-3cmm-1000cmm-1000ddm-1000--10.00-$350.00$400.00-$500.00
73bfg-hy2asz-2cmm-1001cmm-1001ddm-100165.005.00-5.00$600.00$700.00$6,500.00
84bfg-hy2asz-3cmm-1001cmm-1001ddm-1001---5.00$600.00$700.00$500.00
95bfg-hy2asz-4cmm-1001cmm-1001ddm-1001--15.00-$600.00$700.00-$1,500.00
106bfg-hy3asz-3cmm-1002cmm-1002ddm-100280.0020.00--$700.00$800.00$6,000.00
117bfg-hy4asz-4cmm-1003cmm-1003ddm-100354.005.00--$500.00$800.00$14,700.00
expected result
Cell Formulas
RangeFormula
M5:M11M5=(G5+J5-I5-H5) *(L5-K5)

thanks in advance
 
Last edited:

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,215,676
Messages
6,126,168
Members
449,296
Latest member
tinneytwin

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