match data based on three columns together and put the values into last empty columns

KalilMe

Active Member
Joined
Mar 5, 2021
Messages
354
Office Version
  1. 2016
Platform
  1. Windows
hi
I have two sheets should match sheet2 with sheet1 based on columns B,C,D toghether and copy the values to last two empty columns contain headers (purchase and sales) .so in this case after match the data between two sheets it will populate the values in COL E,F in sheet2 and if I run macro again will copy to next empty columns PURCHASE , SALES (H,I) an so on . every time run the macro should search for empty columns(PURCHASE , SALES) and populate the values based on what is existed in sheet1.
I put the expected result should be in sheet2 after matching with sheet1 . with considering the data in sheet1 are increasable and the inserted columns also are increasable in sheet2

sheet1
pop.xlsm
ABCDEF
1DATECOMMIDETYTYPEORIGINPURCHASESALES
21/7/2021FRBANANASO555
31/8/2021FRBANANASO110
41/10/2021VEGTOMATOEG5
51/17/2021FO1TUNE160GSP225
61/18/2021FO1TUNE160GPO1010
71/18/2021FO1TUNE160GSPL5-
SHEET1




sheet2 before
pop.xlsm
ABCDEFGHIJKLMNOP
1ITEMCOMMIDETYTYPEORIGINPURCHASESALES BALANCEPURCHASESALES BALANCEPURCHASESALES BALANCEPURCHASESALES BALANCE
21FRBANANASO0000
32FRBANANASO10000
43FO1TUNE160GSP0000
54FO1TUNE160GPO0000
65VEGTOMATOEG0000
76FO1TUNE160GSPL0000
SHEET2
Cell Formulas
RangeFormula
P2:P7,M2:M7,J2:J7,G2:G7G2=E2-F2



sheet2 after
pop.xlsm
ABCDEF
1ITEMCOMMIDETYTYPEORIGINPURCHASESALES
21FRBANANASO555
32FRBANANASO110
43FO1TUNE160GSP225
54FO1TUNE160GPO1010
65VEGTOMATOEG5
76FO1TUNE160GSPL5
EXPECTED RESULT
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try This With CTRL+SHIFT+ENTER
Book1
ABCDEFGH
1ITEMCOMMIDETYTYPEORIGINPURCHASESALES BALANCEPURCHASE
21FRBANANASO55550
32FRBANANASO110010
43FO1TUNE160GSP22517
54FO1TUNE160GPO10100
65VEGTOMATOEG505
76FO1TUNE160GSPL5-#VALUE!
8
Sheet2
Cell Formulas
RangeFormula
E2:F7E2=IFERROR(INDEX(Sheet1!E$2:E$7,MATCH(1,($B2=Sheet1!$B$2:$B$7)*($C2=Sheet1!$C$2:$C$7)*($D2=Sheet1!$D$2:$D$7),0)),0)
G2:G7G2=E2-F2
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
thanks
honestly I prefer to apply by vba . if you can do it by vba will be a great because my real data about 3000 rows and increasable
about your formula I try putting in E2 but gives me zero .
 
Upvote 0
Try this:
VBA Code:
Sub Macro2()
Dim Lr1 As Long, Lr2 As Long
Lr1 = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
Lr2 = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row
Range("E2:F" & Lr2).Formula = "=INDEX(Sheet1!E$2:E$7,MATCH(1,INDEX((Sheet1!$B$2:$B$7=$B2)*(Sheet1!$C$2:$C$7=$C2)*(Sheet1!$D$2:$D$7=$D2),0,1),0),1)"
Range("E2:F" & Lr2).Value = Range("E2:F" & Lr2).Value
End Sub
 
Upvote 0
thanks
but I said
every time run the macro should search for empty columns(PURCHASE , SALES) and populate the values based on what is existed in sheet1.
I no know if it's not clear .when I repeate running macro should populate the values to next columns contain PURCHASE , SALES . so after run first time macro should poulate values in COL H,I and if I run again should populate the values in COLS K,L and so on every time run macro should populate the values into next columns PURCHASE & SALES

I hope this explenation helps you
 
Upvote 0
Are Data should be Taken from same Columns at Sheet1. For e.g. Take H Data from sheet 2 from H column of Sheet1?
 
Upvote 0
there is no COL H in sheet1 . it always supposes taking the values from COLS E,F from sheet1 after matching with sheet2 but the columns in sheet2 when populate values change continously when run macro repeatedly
 
Upvote 0
Then you say you want run macro to see same result at column E & H and ....
Why?
 
Upvote 0
yes , it should show in COLS PURCHASE, SALES in sheet2 because the data in sheet2 imports from another file every month .then the values will change in sheet1 and should copy to next columns representatves next month
 
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