combined the same sheet name between two files & save as xlsx

Maklil

Board Regular
Joined
Jun 23, 2022
Messages
174
Office Version
  1. 2019
Platform
  1. Windows
Hi experts,
I search for macro to combine the same sheet name between two files are in the same folder . so should combine based on match column B and summing values for columns C,D and insert column BALANCE in column E to subtract column C from column D and save the file as xlsx and the file name should be "FINAL STOCK" and sheet name should be "STOCK" based on sheet name into two files .
the sheet STOCK into two files is existed in last sheet .
STOCK.xlsx
ABCD
1ITEMBRANDIMPORTEXPORT
21ELEC-1000200
32ELEC-10011200
43ELEC-1002122
54ELEC-10031200
65ELEC-1004120
76ELEC-1005300
87ELEC-1006230
98ELEC-1007123
109ELEC-1008123
1110ELEC-1009123
1211ELEC-10101122
1312ELEC-101112210
1413ELEC-10124
1514ELEC-1013123
1615ELEC-10141231
1716ELEC-101511
1817ELEC-101611
1918ELEC-101712
2019ELEC-101812
2120ELEC-10191012
stock



STO.xlsx
ABCD
1ITEMBRANDIMPORTEXPORT
21ELEC-1012123
32ELEC-10131010
43ELEC-10222012
54ELEC-100911
65ELEC-101010
76ELEC-101112
87ELEC-1003220
98ELEC-10044
109ELEC-1005100
1110ELEC-100610
1211ELEC-100710
1312ELEC-100810
1413ELEC-100010
1514ELEC-100110
1615ELEC-100222
1716ELEC-1014112
1817ELEC-1015112
1918ELEC-1016120
2019ELEC-1017102
stock



result (should be the same formatting & borders)
FINAL STOCK.xlsx
ABCDE
1ITEMBRANDIMPORTEXPORTBALANCE
21ELEC-1000210.00- 210.00
32ELEC-10011,210.00- 1,210.00
43ELEC-1002- 144.00-144.00
54ELEC-10031,420.00- 1,420.00
65ELEC-1004120.004.00116.00
76ELEC-1005400.00- 400.00
87ELEC-1006240.00- 240.00
98ELEC-1007133.00- 133.00
109ELEC-1008133.00- 133.00
1110ELEC-1009134.00- 134.00
1211ELEC-10101,132.00- 1,132.00
1312ELEC-1011134.0010.00124.00
1413ELEC-1012123.004.00119.00
1514ELEC-1013133.0010.00123.00
1615ELEC-1014134.003.00131.00
1716ELEC-1015123.00- 123.00
1817ELEC-1016131.00- 131.00
1918ELEC-101722.002.0020.00
2019ELEC-101812.00- 12.00
2120ELEC-101910.0012.00-2.00
2221ELEC-102220.0012.008.00
STOCK

thanks
 
Replace the current part of the code with this:
VBA Code:
With desWS
    .Range("A2").Value = "1"
    .Range("A2").AutoFill Destination:=.Range("A2").Resize(.Range("B" & .Rows.Count).End(xlUp).Row - 1), Type:=xlFillSeries
    .Cells(1, 1).Sort Key1:=Columns(2), Order1:=xlAscending, Orientation:=xlTopToBottom, Header:=xlYes
End With
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
thanks again
I need arranging numbers sequences in column A
this is what I got
Final Stock.xlsx
ABCDE
1ITEMBRANDIMPORTEXPORTBALANCE
213ELEC-1000299.004.00295.00
314ELEC-10011,323.000.001,323.00
415ELEC-100244.00145.00-101.00
57ELEC-10031,476.00-1,476.00
68ELEC-1004208.004204.00
79ELEC-10051,244.00-1,244.00
810ELEC-1006513.0010503.00
911ELEC-1007256.004252.00
1012ELEC-1008577.000.00577.00
114ELEC-1009257.002255.00
125ELEC-10102,377.002.002,375.00
136ELEC-1011490.0020470.00
141ELEC-1012123.004119.00
152ELEC-1013133.0010123.00
1616ELEC-1014354.0023331.00
1717ELEC-1015123.0010113.00
1818ELEC-1016241.000.00241.00
1919ELEC-1017242.0012230.00
2020ELEC-1018232.0015.00217.00
2121ELEC-1019610.0012.00598.00
2222ELEC-1020342014
2323ELEC-102112010110
243ELEC-10225412.0042.00
2524ELEC-1023220220
stock


and this is should be
Final Stock.xlsx
ABCDE
1ITEMBRANDIMPORTEXPORTBALANCE
21ELEC-1000299.004.00295.00
32ELEC-10011,323.000.001,323.00
43ELEC-100244.00145.00-101.00
54ELEC-10031,476.00-1,476.00
65ELEC-1004208.004204.00
76ELEC-10051,244.00-1,244.00
87ELEC-1006513.0010503.00
98ELEC-1007256.004252.00
109ELEC-1008577.000.00577.00
1110ELEC-1009257.002255.00
1211ELEC-10102,377.002.002,375.00
1312ELEC-1011490.0020470.00
1413ELEC-1012123.004119.00
1514ELEC-1013133.0010123.00
1615ELEC-1014354.0023331.00
1716ELEC-1015123.0010113.00
1817ELEC-1016241.000.00241.00
1918ELEC-1017242.0012230.00
2019ELEC-1018232.0015.00217.00
2120ELEC-1019610.0012.00598.00
2221ELEC-1020342014
2322ELEC-102112010110
2423ELEC-10225412.0042.00
2524ELEC-1023220220
stock
 
Upvote 0
Try:
VBA Code:
With desWS
    .Cells(1, 1).Sort Key1:=Columns(2), Order1:=xlAscending, Orientation:=xlTopToBottom, Header:=xlYes
    .Range("A2").Value = "1"
    .Range("A2").AutoFill Destination:=.Range("A2").Resize(.Range("B" & .Rows.Count).End(xlUp).Row - 1), Type:=xlFillSeries
End With
 
Upvote 0
all of things are great !(y)
many thanks for your a great assistance :)
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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