Split data are existed in two sheets to two sheets for each group

abdo meghari

Well-known Member
Joined
Aug 3, 2021
Messages
705
Office Version
  1. 2019
Hello,
I would macro to deal with about 10000 rows and contain about 100 groups for each sheet.
in SELLING,BUYING sheet should split data based on column B for each group ,as to column C should match with sheets names(SALES,COSTING) are already existed and show data for each sheet based on sheet name is existed in column C for SELLING,BUYING sheets.



ABDO (1).xls
ABCDEFGHI
1DATEGROUP/COMPANYTYPEBRAND NODESCRIBEUNITQTYSELLING PRICETOTAL
201/01/2025GOMMESTSALES1769 BLUE TR414 100 PCSPIECE250.45011.250
301/01/2025TIRESSALES1130GC 1200R20 QAZ183 CHIPIECE51,450.0007,250.000
401/01/2025BATTERYSALES1118XPRO 70A L KORPIECE1350.000350.000
501/01/2025BATTERYSALES1119XPRO 70A R KORPIECE2300.000600.000
602/01/2025GOMMESTSALES1774 BOAF0-50PIECE2100.900189.000
703/01/2025GOMMESTSALES1775 XIA TW-9250 250MLPIECE10.9500.950
804/01/2025TIRESSALES1123BS 750R16 R230 JAPPIECE10450.0004,500.000
905/01/2025TIRESSALES1124BS 750R16 VSJ JAPPIECE8750.0006,000.000
1006/01/2025GOMMESTSALES1752 EUS-65 ROUND PATCH 65X65 PIECE102.50025.000
1106/01/2025GOMMESTSALES1758 P1108 TAIWANPIECE115.50060.500
1206/01/2025GOMMESTSALES1773 PTO-2301-R 0.6X100MM.PIECE881.500132.000
1306/01/2025GOMMESTSALES1765 VMTC 7.50-16 V3-02-7PIECE160.00060.000
1406/01/2025TIRESSALES1125BS 1200R20 G580 JAPPIECE22,500.0005,000.000
1506/01/2025TIRESSALES1126BS 315/80R22.5 R184 JAPPIECE801,950.000156,000.000
1607/01/2025TIRESSALES1127BS 1400R20 VSJ JAPPIECE14,000.0004,000.000
1708/01/2025GOMMESTSALES1767HEADER OF PRESSUREPIECE14.0004.000
1809/01/2025GOMMESTSALES1768LEAD 10GM WIDEPIECE30.7502.250
1910/01/2025GOMMESTSALES1769LEAD 10GM TIDEPIECE70.8505.950
2011/01/2025GOMMESTSALES1770LEAD 15GM WIDEPIECE40.6502.600
2112/01/2025GOMMESTSALES1771LEAD 15GM TIDEPIECE60.9505.700
2213/01/2025GOMMESTSALES1772LEAD 20GM WIDEPIECE70.7004.900
2314/01/2025GOMMESTSALES1773LEAD 20GM TIDEPIECE160.80012.800
2415/01/2025TIRESSALES1128BS 1200R24 G580 JAPPIECE22,800.0005,600.000
2516/01/2025TIRESSALES1129GC 1200R20 AZ026 CHIPIECE21,350.0002,700.000
2617/01/2025BATTERYSALES1120XPRO 90A R KORPIECE2425.000850.000
2718/01/2025BATTERYSALES1121HANKOOK 150A L KORPIECE10850.0008,500.000
2819/01/2025BATTERYSALES1123ASIMCO 150A L KORPIECE1750.000750.000
SELLING
Cell Formulas
RangeFormula
I2:I28I2=H2*G2




ABDO (1).xls
ABCDEFGHI
1DATEGROUP/COMPANYTYPEBRAND NODESCRIBEUNITQTYCOSTING PRICETOTAL
201/01/2025GOMMESTCOSTING1765 VMTC 7.50-16 V3-02-7PIECE10045.0004,500.000
302/01/2025GOMMESTCOSTING1767HEADER OF PRESSUREPIECE1100.55060.500
403/01/2025TIRESCOSTING1126BS 315/80R22.5 R184 JAPPIECE1001,900.000190,000.000
504/01/2025TIRESCOSTING1127BS 1400R20 VSJ JAPPIECE203,900.00078,000.000
605/01/2025TIRESCOSTING1130GC 1200R20 QAZ183 CHIPIECE301,400.00042,000.000
705/01/2025TIRESCOSTING1133GC 1200R20 QAZ188 CHIPIECE201,500.00030,000.000
806/01/2025BATTERYCOSTING1118XPRO 70A L KORPIECE1300.000300.000
907/01/2025BATTERYCOSTING1119XPRO 70A R KORPIECE2250.000500.000
1008/01/2025GOMMESTCOSTING1768LEAD 10GM WIDEPIECE2000.25050.000
1109/01/2025GOMMESTCOSTING1769 BLUE TR414 100 PCSPIECE1250.33041.250
1210/01/2025GOMMESTCOSTING1752 EUS-65 ROUND PATCH 65X65 PIECE1001.500150.000
1311/01/2025GOMMESTCOSTING1758 P1108 TAIWANPIECE153.50052.500
1412/01/2025TIRESCOSTING1125BS 1200R20 G580 JAPPIECE102,400.00024,000.000
1513/01/2025TIRESCOSTING1128BS 1200R24 G580 JAPPIECE202,700.00054,000.000
1614/01/2025TIRESCOSTING1129GC 1200R20 AZ026 CHIPIECE301,300.00039,000.000
1715/01/2025GOMMESTCOSTING1773 PTO-2301-R 0.6X100MM.PIECE901.250112.500
1816/01/2025GOMMESTCOSTING1775 XIA TW-9250 250MLPIECE120.4905.880
1917/01/2025GOMMESTCOSTING1769LEAD 10GM TIDEPIECE170.3505.950
2018/01/2025GOMMESTCOSTING1770LEAD 15GM WIDEPIECE440.44019.360
2119/01/2025GOMMESTCOSTING1771LEAD 15GM TIDEPIECE660.45029.700
2220/01/2025GOMMESTCOSTING1772LEAD 20GM WIDEPIECE770.46035.420
2321/01/2025GOMMESTCOSTING1773LEAD 20GM TIDEPIECE1660.47078.020
2421/01/2025GOMMESTCOSTING1774 BOAF0-50PIECE2500.480120.000
2521/01/2025GOMMESTCOSTING1775 BOAF0-51PIECE1000.65065.000
2621/01/2025TIRESCOSTING1123BS 750R16 R230 JAPPIECE50400.00020,000.000
2721/01/2025TIRESCOSTING1124BS 750R16 VSJ JAPPIECE80700.00056,000.000
2822/01/2025BATTERYCOSTING1122NOVA 150A L KORPIECE1700.000700.000
2923/01/2025BATTERYCOSTING1123ASIMCO 150A L KORPIECE2700.0001,400.000
3024/01/2025BATTERYCOSTING1120XPRO 90A R KORPIECE2400.000800.000
3125/01/2025BATTERYCOSTING1121HANKOOK 150A L KORPIECE10800.0008,000.000
BUYING
Cell Formulas
RangeFormula
I2:I31I2=H2*G2




ABDO (1).xls
ABCDEFGH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
SALES


ABDO (1).xls
ABCDEFG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
COSTING


when split data if the C3,E3 are empty in SPLIT sheet
ABDO (1).xls
ABCDEF
1
2FROM DATETO DATE
3
4
5
6
7
8
split



then should split data like this
ABDO (1).xls
ABCDEFG
1GROUP/COMPANY: GOMMEST
2ITEMBRAND NODESCRIBEUNITQTYSELLING PRICETOTAL
311769 BLUE TR414 100 PCSPIECE250.45011.250
421752 EUS-65 ROUND PATCH 65X65 PIECE102.50025.000
531758 P1108 TAIWANPIECE115.50060.500
641773 PTO-2301-R 0.6X100MM.PIECE881.500132.000
751765 VMTC 7.50-16 V3-02-7PIECE160.00060.000
861767HEADER OF PRESSUREPIECE14.0004.000
971768LEAD 10GM WIDEPIECE30.7502.250
1081769LEAD 10GM TIDEPIECE70.8505.950
1191770LEAD 15GM WIDEPIECE40.6502.600
12101771LEAD 15GM TIDEPIECE60.9505.700
13111772LEAD 20GM WIDEPIECE70.7004.900
14121773LEAD 20GM TIDEPIECE160.80012.800
15131774 BOAF0-50PIECE2100.900189.000
16141775 XIA TW-9250 250MLPIECE10.9500.950
17SELLING TOTAL516.900
18
19
20
21GROUP/COMPANY: TIRES
22ITEMBRAND NODESCRIBEUNITQTYSELLING PRICETOTAL
2311123BS 750R16 R230 JAPPIECE10450.0004,500.000
2421124BS 750R16 VSJ JAPPIECE8750.0006,000.000
2531125BS 1200R20 G580 JAPPIECE22,500.0005,000.000
2641126BS 315/80R22.5 R184 JAPPIECE801,950.000156,000.000
2751127BS 1400R20 VSJ JAPPIECE14,000.0004,000.000
2861128BS 1200R24 G580 JAPPIECE22,800.0005,600.000
2971129GC 1200R20 AZ026 CHIPIECE21,350.0002,700.000
3081130GC 1200R20 QAZ183 CHIPIECE51,450.0007,250.000
31SELLING TOTAL191,050.000
32
33
34GROUP/COMPANY: BATTERY
35ITEMBRAND NODESCRIBEUNITQTYSELLING PRICETOTAL
3611118XPRO 70A L KORPIECE1350.000350.000
3721119XPRO 70A R KORPIECE2300.000600.000
3831120XPRO 90A R KORPIECE2425.000850.000
3941121HANKOOK 150A L KORPIECE10850.0008,500.000
4051123ASIMCO 150A L KORPIECE1750.000750.000
41SELLING TOTAL11,050.000
SALES
Cell Formulas
RangeFormula
G36:G40,G23:G30,G3:G16G3=F3*E3
G17G17=SUM(G3:G16)
G31G31=SUM(G23:G30)
G41G41=SUM(G36:G40)



ABDO (1).xls
ABCDEFG
1GROUP/COMPANY: GOMMEST
2ITEMBRAND NODESCRIBEUNITQTYCOSTING PRICETOTAL
351765 VMTC 7.50-16 V3-02-7PIECE10045.0004,500.000
461767HEADER OF PRESSUREPIECE1100.55060.500
571768LEAD 10GM WIDEPIECE2000.25050.000
611769 BLUE TR414 100 PCSPIECE1250.33041.250
721752 EUS-65 ROUND PATCH 65X65 PIECE1001.500150.000
831758 P1108 TAIWANPIECE153.50052.500
941773 PTO-2301-R 0.6X100MM.PIECE901.250112.500
10141775 XIA TW-9250 250MLPIECE120.4905.880
1181769LEAD 10GM TIDEPIECE170.3505.950
1291770LEAD 15GM WIDEPIECE440.44019.360
13101771LEAD 15GM TIDEPIECE660.45029.700
14111772LEAD 20GM WIDEPIECE770.46035.420
15121773LEAD 20GM TIDEPIECE1660.47078.020
16131774 BOAF0-50PIECE2500.480120.000
17141775 BOAF0-51PIECE1000.65065.000
18COSTING TOTAL715.580
19
20
21GROUP/COMPANY: TIRES
22ITEMBRAND NODESCRIBEUNITQTYCOSTING PRICETOTAL
2311125BS 1200R20 G580 JAPPIECE102,400.00024,000.000
2421128BS 1200R24 G580 JAPPIECE202,700.00054,000.000
2531129GC 1200R20 AZ026 CHIPIECE301,300.00039,000.000
2641123BS 750R16 R230 JAPPIECE50400.00020,000.000
2751124BS 750R16 VSJ JAPPIECE80700.00056,000.000
2861126BS 315/80R22.5 R184 JAPPIECE1001,900.000190,000.000
2971127BS 1400R20 VSJ JAPPIECE203,900.00078,000.000
3081130GC 1200R20 QAZ183 CHIPIECE301,400.00042,000.000
3191133GC 1200R20 QAZ188 CHIPIECE201,500.00030,000.000
32COSTING TOTAL455,000.000
33
34
35GROUP/COMPANY: BATTERY
36ITEMBRAND NODESCRIBEUNITQTYCOSTING PRICETOTAL
3711118XPRO 70A L KORPIECE1300.000300.000
3821119XPRO 70A R KORPIECE2250.000500.000
3931122NOVA 150A L KORPIECE1700.000700.000
4041123ASIMCO 150A L KORPIECE2700.0001,400.000
4151120XPRO 90A R KORPIECE2400.000800.000
4261121HANKOOK 150A L KORPIECE10800.0008,000.000
43COSTING TOTAL11,700.000
COSTING
Cell Formulas
RangeFormula
G37:G42,G23:G31,G3:G17G3=F3*E3
G18G18=SUM(G6:G17)
G32G32=SUM(G25:G31)
G43G43=SUM(G37:G42)




otherwise when there are dates then split within dates in C3,E3 in SPLIT sheet.
thanks.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
ABDO (1).xls
A
1DATE
201/01/2025
301/01/2025
401/01/2025
501/01/2025
602/01/2025
703/01/2025
804/01/2025
905/01/2025
1006/01/2025
1106/01/2025
1206/01/2025
1306/01/2025
1406/01/2025
1506/01/2025
1607/01/2025
1708/01/2025
1809/01/2025
1910/01/2025
2011/01/2025
2112/01/2025
2213/01/2025
2314/01/2025
2415/01/2025
2516/01/2025
2617/01/2025
2718/01/2025
2819/01/2025
SELLING


What dates have you got in cells C3 and E3 in the SPLIT sheet?
I don't write any dates to split data when C3,E3 are empty as in OP
 
Upvote 0
ABDO (1).xls
A
1DATE
201/01/2025
301/01/2025
401/01/2025
501/01/2025
602/01/2025
703/01/2025
804/01/2025
905/01/2025
1006/01/2025
1106/01/2025
1206/01/2025
1306/01/2025
1406/01/2025
1506/01/2025
1607/01/2025
1708/01/2025
1809/01/2025
1910/01/2025
2011/01/2025
2112/01/2025
2213/01/2025
2314/01/2025
2415/01/2025
2516/01/2025
2617/01/2025
2718/01/2025
2819/01/2025
SELLING



I don't write any dates to split data when C3,E3 are empty as in OP
Put these dates in and run it again.

Version 1.xlsm
BCDEF
1
2FROM DATE TO DATE
301/01/202510/01/2027
4
5
6
Split
 
Upvote 0
error object doesn't support this property method

VBA Code:
WsDestination.Range("K1").CurrentRegion.Offset(0, 1).Formula2 = _
      "=SUMIF(" & rngData.Columns(2).Address & ",K1," & rngData.Columns(9).Address & ")"
 
Upvote 0
error object doesn't support this property method

VBA Code:
WsDestination.Range("K1").CurrentRegion.Offset(0, 1).Formula2 = _
      "=SUMIF(" & rngData.Columns(2).Address & ",K1," & rngData.Columns(9).Address & ")"
What dates are you using?

Please post a mini-sheet of cells K1:L10 of the SALES sheet.

You should have something like this?

Version 1.xlsm
JKLM
1GROUP/COMPANY0
2BATTERY11050
3GOMMEST516.9
4TIRES191050
5
SALES
Cell Formulas
RangeFormula
L1:L4L1=SUMIF($B$2:$B$28,K1,$I$2:$I$28)
Named Ranges
NameRefers ToCells
Extract=SALES!$K$1L1
 
Upvote 0
just question , your code works when C3,E3 are empty ?
this is will show after close error window .
ABDO (1).xls
ABCDEFGHIJKL
1DATEGROUP/COMPANYTYPEBRAND NODESCRIBEUNITQTYSELLING PRICETOTALGROUP/COMPANY
219/01/2025BATTERYSALES1123ASIMCO 150A L KORPIECE1750.000750.000BATTERY
318/01/2025BATTERYSALES1121HANKOOK 150A L KORPIECE10850.0008,500.000GOMMEST
401/01/2025BATTERYSALES1118XPRO 70A L KORPIECE1350.000350.000TIRES
501/01/2025BATTERYSALES1119XPRO 70A R KORPIECE2300.000600.000
617/01/2025BATTERYSALES1120XPRO 90A R KORPIECE2425.000850.000
701/01/2025GOMMESTSALES1769 BLUE TR414 100 PCSPIECE250.45011.250
802/01/2025GOMMESTSALES1774 BOAF0-50PIECE2100.900189.000
906/01/2025GOMMESTSALES1752 EUS-65 ROUND PATCH 65X65 PIECE102.50025.000
1006/01/2025GOMMESTSALES1758 P1108 TAIWANPIECE115.50060.500
1106/01/2025GOMMESTSALES1773 PTO-2301-R 0.6X100MM.PIECE881.500132.000
1206/01/2025GOMMESTSALES1765 VMTC 7.50-16 V3-02-7PIECE160.00060.000
1303/01/2025GOMMESTSALES1775 XIA TW-9250 250MLPIECE10.9500.950
1408/01/2025GOMMESTSALES1767HEADER OF PRESSUREPIECE14.0004.000
1510/01/2025GOMMESTSALES1769LEAD 10GM TIDEPIECE70.8505.950
1609/01/2025GOMMESTSALES1768LEAD 10GM WIDEPIECE30.7502.250
1712/01/2025GOMMESTSALES1771LEAD 15GM TIDEPIECE60.9505.700
1811/01/2025GOMMESTSALES1770LEAD 15GM WIDEPIECE40.6502.600
1914/01/2025GOMMESTSALES1773LEAD 20GM TIDEPIECE160.80012.800
2013/01/2025GOMMESTSALES1772LEAD 20GM WIDEPIECE70.7004.900
2106/01/2025TIRESSALES1125BS 1200R20 G580 JAPPIECE22,500.0005,000.000
2215/01/2025TIRESSALES1128BS 1200R24 G580 JAPPIECE22,800.0005,600.000
2307/01/2025TIRESSALES1127BS 1400R20 VSJ JAPPIECE14,000.0004,000.000
2406/01/2025TIRESSALES1126BS 315/80R22.5 R184 JAPPIECE801,950.000156,000.000
2504/01/2025TIRESSALES1123BS 750R16 R230 JAPPIECE10450.0004,500.000
2605/01/2025TIRESSALES1124BS 750R16 VSJ JAPPIECE8750.0006,000.000
2716/01/2025TIRESSALES1129GC 1200R20 AZ026 CHIPIECE21,350.0002,700.000
2801/01/2025TIRESSALES1130GC 1200R20 QAZ183 CHIPIECE51,450.0007,250.000
SALES
Cell Formulas
RangeFormula
I2:I28I2=H2*G2
 
Upvote 0
just question , your code works when C3,E3 are empty ?
this is will show after close error window .
ABDO (1).xls
ABCDEFGHIJKL
1DATEGROUP/COMPANYTYPEBRAND NODESCRIBEUNITQTYSELLING PRICETOTALGROUP/COMPANY
219/01/2025BATTERYSALES1123ASIMCO 150A L KORPIECE1750.000750.000BATTERY
318/01/2025BATTERYSALES1121HANKOOK 150A L KORPIECE10850.0008,500.000GOMMEST
401/01/2025BATTERYSALES1118XPRO 70A L KORPIECE1350.000350.000TIRES
501/01/2025BATTERYSALES1119XPRO 70A R KORPIECE2300.000600.000
617/01/2025BATTERYSALES1120XPRO 90A R KORPIECE2425.000850.000
701/01/2025GOMMESTSALES1769 BLUE TR414 100 PCSPIECE250.45011.250
802/01/2025GOMMESTSALES1774 BOAF0-50PIECE2100.900189.000
906/01/2025GOMMESTSALES1752 EUS-65 ROUND PATCH 65X65 PIECE102.50025.000
1006/01/2025GOMMESTSALES1758 P1108 TAIWANPIECE115.50060.500
1106/01/2025GOMMESTSALES1773 PTO-2301-R 0.6X100MM.PIECE881.500132.000
1206/01/2025GOMMESTSALES1765 VMTC 7.50-16 V3-02-7PIECE160.00060.000
1303/01/2025GOMMESTSALES1775 XIA TW-9250 250MLPIECE10.9500.950
1408/01/2025GOMMESTSALES1767HEADER OF PRESSUREPIECE14.0004.000
1510/01/2025GOMMESTSALES1769LEAD 10GM TIDEPIECE70.8505.950
1609/01/2025GOMMESTSALES1768LEAD 10GM WIDEPIECE30.7502.250
1712/01/2025GOMMESTSALES1771LEAD 15GM TIDEPIECE60.9505.700
1811/01/2025GOMMESTSALES1770LEAD 15GM WIDEPIECE40.6502.600
1914/01/2025GOMMESTSALES1773LEAD 20GM TIDEPIECE160.80012.800
2013/01/2025GOMMESTSALES1772LEAD 20GM WIDEPIECE70.7004.900
2106/01/2025TIRESSALES1125BS 1200R20 G580 JAPPIECE22,500.0005,000.000
2215/01/2025TIRESSALES1128BS 1200R24 G580 JAPPIECE22,800.0005,600.000
2307/01/2025TIRESSALES1127BS 1400R20 VSJ JAPPIECE14,000.0004,000.000
2406/01/2025TIRESSALES1126BS 315/80R22.5 R184 JAPPIECE801,950.000156,000.000
2504/01/2025TIRESSALES1123BS 750R16 R230 JAPPIECE10450.0004,500.000
2605/01/2025TIRESSALES1124BS 750R16 VSJ JAPPIECE8750.0006,000.000
2716/01/2025TIRESSALES1129GC 1200R20 AZ026 CHIPIECE21,350.0002,700.000
2801/01/2025TIRESSALES1130GC 1200R20 QAZ183 CHIPIECE51,450.0007,250.000
SALES
Cell Formulas
RangeFormula
I2:I28I2=H2*G2
It does not work for me when C3 and E3 are empty which is strange.

This following code line works for me. I will think of an alternative way of doing it.

Excel Formula:
WsDestination.Range("K1").CurrentRegion.Offset(0, 1).Formula2 = _
      "=SUMIF(" & rngData.Columns(2).Address & ",K1," & rngData.Columns(9).Address & ")"
 
Upvote 0

Forum statistics

Threads
1,226,520
Messages
6,191,528
Members
453,661
Latest member
edfclaya

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