calculation at the same column based on matching two sheets to show balance

tubrak

Board Regular
Joined
May 30, 2021
Messages
218
Office Version
  1. 2019
Platform
  1. Windows
hi
I want to show the final values in column C in sheet ITEM after matching with column B for two sheets 1,2 . the calculation should sum the values in column C with sheet1 and subtracting from sheet2 and if there are new items in sheet1,2 but not are existed in sheet ITEM then should add to sheet ITEM for instance TR 200M45 MM 123H K/L SS=20+20-20 . with also brings the others items have already existed .so every time run the macro should creat new sheet based on date today with word STOCK and if change or update again in the same date(today) should update for sheet has already created and should create new sheet for next day . I put the result in sheet based on date(today) . my data are huge about more than 10000 rows
also posted here
calculation at the same column based on matching two sheets to show balance

stock1.xlsm
ABC
1S.NITEMQTY
21CTR 12-200M45 MM 123H K/L30
32TR 200M45MM LK H K/L10
43TTR 12200S45 MN 12320
54TR 1425/148V MN 123H K/L15
65TR 200M45 MM 123H K/L SS20
76TR 2.5M100* 123H K/L10
87TR 2.5M100**123H K/L20
98TR 1200M45MM LK H K/L0
109BTR-100***8 RRT-DE3423020
1110BTR-100***8 RRT-DE3423120
1211BTR-100***8 RRT-DE3423220
1312BTR-100***8 RRT-DE34233234
1413BTR-100***8 RRT-DE3423444
1514BTR-100***8 RRT-DE3423555
1615BTR-100***8 RRT-DE34236212
1716BTR-100***8 RRT-DE3423720
1817BTR-100***8 RRT-DE3423820
ITEMS




stock1.xlsm
ABC
1S.NITEMBUYING
21TR 200M451NMM LK H K/L10
32TR 2.5M100**123H K/LM20
43CCTR 12-200M45 MM 123H K/L15
54TR 200M45 MM 123H K/L SS20
65TR 2.5M100*123H K/L10
76TTRM 12200S45 MN 123420
SHEET1




stock1.xlsm
ABC
1S.NITEMSELLING
21TR 2.5M1100**123H K/L8
32TR 2.5M1100*123H K/L25
43TR 1425/148V MN 123H K/L15
54TR 200M45 MM 123H K/L SS20
65TRMN 22.5M100* 123H K/L10
79TTRR 1200S45 MN 12320
SHEET2



result


stock1.xlsm
ABC
1S.NITEMQTY
21CTR 12-200M45 MM 123H K/L30
32CCTR 12-200M45 MM 123H K/L15
43TR 200M45MM LK H K/L10
54TR 200M451NMM LK H K/L10
65TTR 12200S45 MN 12320
76TR 1425/148V MN 123H K/L0
87TR 200M45 MM 123H K/L SS20
98TR 2.5M100* 123H K/L-5
109TR 2.5M100**123H K/L32
1110TRMN 22.5M100* 123H K/L-10
1211TTRM 12200S45 MN 1234-20
1312TTRR 1200S45 MN 123-20
1413TR 1200M45MM LK H K/L0
1514BTR-100***8 RRT-DE3423020
1615BTR-100***8 RRT-DE3423120
1716BTR-100***8 RRT-DE3423220
1817BTR-100***8 RRT-DE34233234
1918BTR-100***8 RRT-DE3423444
2019BTR-100***8 RRT-DE3423555
2120BTR-100***8 RRT-DE34236212
2221BTR-100***8 RRT-DE3423720
2322BTR-100***8 RRT-DE3423820
2423BTR-100***8 RRT-DE3423920
STOCK 7-15-2022


thanks
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
One of the issues I am having with your data is that it does not match consistently. You have spaces in one record and in the expected "matching" record therer are no spaces. Your data needs to be consistent for any type of matching to happen in Excel. Suggest you check your data and then try to reload so that we don't have to retype and figure out which ones don't match in order to give you a workable solution. Help us to help you by giving us reliable data.
 
Upvote 0
thanks . can the excel ignore any different spaces ? just matching based on the words into cells .
 
Upvote 0
Cannot. Does not have AI. Matches on a String. If not exact then it does not pair up.
 
Upvote 0
hope this help . cleaning some spaces
stock.xlsm
ABC
1S.NITEMQTY
21CTR 12-200M45 MM 123H K/L30
32TR 200M45MM LK H K/L10
43TTR 12200S45 MN 12320
54TR 1425/148V MN 123H K/L15
65TR 200M45 MM 123H K/L SS20
76TR 2.5M100* 123H K/L10
87TR 2.5M100**123H K/L20
98TR 1200M45MM LK H K/L0
109BTR-100***8 RRT-DE3423020
1110BTR-100***8 RRT-DE3423120
1211BTR-100***8 RRT-DE3423220
1312BTR-100***8 RRT-DE34233234
1413BTR-100***8 RRT-DE3423444
1514BTR-100***8 RRT-DE3423555
1615BTR-100***8 RRT-DE34236212
1716BTR-100***8 RRT-DE3423720
1817BTR-100***8 RRT-DE3423820
ITEMS




stock.xlsm
ABC
1S.NITEMBUYING
21TR 200M451NMM LK H K/L10
32TR 2.5M100**123H K/LM20
43CCTR 12-200M45 MM 123H K/L15
54TR 200M45 MM 123H K/L SS20
65TR 2.5M100* 123H K/L10
76TTRM 12200S45 MN 123420
sheet1


stock.xlsm
ABC
1S.NITEMSELLING
21TR 2.5M100**123H K/L8
32TR 2.5M100* 123H K/L25
43TR 1425/148V MN 123H K/L15
54TR 200M45 MM 123H K/L SS20
65TRMN 22.5M100* 123H K/L10
79TTRR 1200S45 MN 12320
sheet2


result
stock.xlsm
ABC
1S.NITEMQTY
21CTR 12-200M45 MM 123H K/L30
32CCTR 12-200M45 MM 123H K/L15
43TR 200M45MM LK H K/L10
54TR 200M451NMM LK H K/L10
65TTR 12200S45 MN 12320
76TR 1425/148V MN 123H K/L0
87TR 200M45 MM 123H K/L SS20
98TR 2.5M100* 123H K/L-5
109TR 2.5M100**123H K/L32
1110TRMN 22.5M100* 123H K/L-10
1211TTRM 12200S45 MN 1234-20
1312TTRR 1200S45 MN 123-20
1413TR 1200M45MM LK H K/L0
1514BTR-100***8 RRT-DE3423020
1615BTR-100***8 RRT-DE3423120
1716BTR-100***8 RRT-DE3423220
1817BTR-100***8 RRT-DE34233234
1918BTR-100***8 RRT-DE3423444
2019BTR-100***8 RRT-DE3423555
2120BTR-100***8 RRT-DE34236212
2221BTR-100***8 RRT-DE3423720
2322BTR-100***8 RRT-DE3423820
STOCK 7-15-2022
 
Upvote 0
Since you have Excel 2019, you have power query available to you. It is on the Data Tab and is called Get and Transform Data.

Load each of your tables into PQ and then join them as shown in the following Mcode.

Load the Item Table
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"QTY", Int64.Type}})
in
    #"Changed Type"
Load the buying table
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"BUYING", Int64.Type}})
in
    #"Changed Type"
Load the selling table
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"SELLING", Int64.Type}})
in
    #"Changed Type"
Join the item table with the buying table and add the quantities
Power Query:
let
    Source = Table.NestedJoin(Items, {"ITEM"}, Buying, {"ITEM"}, "Buying", JoinKind.LeftOuter),
    #"Expanded Buying" = Table.ExpandTableColumn(Source, "Buying", {"BUYING"}, {"BUYING.1"}),
    #"Replaced Value" = Table.ReplaceValue(#"Expanded Buying",null,0,Replacer.ReplaceValue,{"BUYING.1"}),
    #"Inserted Addition" = Table.AddColumn(#"Replaced Value", "Addition", each [QTY] + [BUYING.1], type number),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted Addition",{"QTY", "BUYING.1"})
in
    #"Removed Columns"
Join the selling table to the joined table previously and subtract quantities
Power Query:
let
    Source = Table.NestedJoin(Merge1, {"ITEM"}, Selling, {"ITEM"}, "Selling", JoinKind.LeftOuter),
    #"Expanded Selling" = Table.ExpandTableColumn(Source, "Selling", {"SELLING"}, {"SELLING.1"}),
    #"Replaced Value" = Table.ReplaceValue(#"Expanded Selling",null,0,Replacer.ReplaceValue,{"SELLING.1"}),
    #"Inserted Subtraction" = Table.AddColumn(#"Replaced Value", "Subtraction", each [Addition] - [SELLING.1], type number),
    #"Renamed Columns" = Table.RenameColumns(#"Inserted Subtraction",{{"Subtraction", "QTY"}}),
    #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"Addition", "SELLING.1"})
in
    #"Removed Columns"
End result will look as follows.
S.NITEMQTY
1CTR 12-200M45 MM 123H K/L30
7TR 2.5M100**123H K/L12
2TR 200M45MM LK H K/L10
6TR 2.5M100* 123H K/L-5
3TTR 12200S45 MN 12320
4TR 1425/148V MN 123H K/L0
5TR 200M45 MM 123H K/L SS20
8TR 1200M45MM LK H K/L0
9BTR-100***8 RRT-DE3423020
10BTR-100***8 RRT-DE3423120
11BTR-100***8 RRT-DE3423220
12BTR-100***8 RRT-DE34233234
13BTR-100***8 RRT-DE3423444
14BTR-100***8 RRT-DE3423555
15BTR-100***8 RRT-DE34236212
16BTR-100***8 RRT-DE3423720
17BTR-100***8 RRT-DE3423820
 
Upvote 0
Correction to above as time to edit has expired. Noticed an error in my first presentation.
the first join should be as follows:

Power Query:
let
    Source = Table.NestedJoin(Items, {"ITEM"}, Buying, {"ITEM"}, "Buying", JoinKind.FullOuter),
    #"Expanded Buying" = Table.ExpandTableColumn(Source, "Buying", {"ITEM", "BUYING"}, {"ITEM.1", "BUYING.1"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Buying", "Custom", each if[ITEM]=null then [ITEM.1] else [ITEM]),
    #"Removed Columns1" = Table.RemoveColumns(#"Added Custom",{"ITEM", "ITEM.1"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns1",{"S.N", "Custom", "QTY", "BUYING.1"}),
    #"Replaced Value" = Table.ReplaceValue(#"Reordered Columns",null,0,Replacer.ReplaceValue,{"BUYING.1"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value",null,0,Replacer.ReplaceValue,{"QTY"}),
    #"Inserted Addition" = Table.AddColumn(#"Replaced Value1", "Addition", each [QTY] + [BUYING.1], type number),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted Addition",{"QTY", "BUYING.1"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "ITEM"}})
in
    #"Renamed Columns"

and the end result should look like the following

S.NITEMQTY
1CTR 12-200M45 MM 123H K/L30
7TR 2.5M100**123H K/L12
2TR 200M45MM LK H K/L10
6TR 2.5M100* 123H K/L-5
3TTR 12200S45 MN 12320
4TR 1425/148V MN 123H K/L0
5TR 200M45 MM 123H K/L SS20
8TR 1200M45MM LK H K/L0
9BTR-100***8 RRT-DE3423020
10BTR-100***8 RRT-DE3423120
11BTR-100***8 RRT-DE3423220
12BTR-100***8 RRT-DE34233234
13BTR-100***8 RRT-DE3423444
14BTR-100***8 RRT-DE3423555
15BTR-100***8 RRT-DE34236212
16BTR-100***8 RRT-DE3423720
17BTR-100***8 RRT-DE3423820
TR 200M451NMM LK H K/L10
TR 2.5M100**123H K/LM20
CCTR 12-200M45 MM 123H K/L15
TTRM 12200S45 MN 123420
 
Upvote 0
I did not save the workbook, so I will have to try and recreate again and then I will post the workbook to a third party site so you can review completely. Right now it is 2 am and I need some sleep. Hiking in the morning. Will look at it later in the day.

Alan
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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