You are here:

Excel/Matching data in 2 columns, then calculating based on 2 supporting columns

Advertisement


Question
Hello

I have 4 columns of data that I need to compare

EG.
Material A   Count A   Material B  Count B
xyz          2         abc         3
abc          1         aaa         1
fff          1         xyz         4


i need to compare material A with material B - if there is a match i need to subtract count B from Count A

i thought i was vaguely ok at excel but reality has bitten.  am investigating match, sum nesting formula etc, but long and short i'm stuck

can you help?

much appreciated

Answer
Michelle,

assume xyz in Material A is cell A2  then

=Match(A2,C:C,0)  would return 4  (cell C4)

to get the 4 under count B you would do

=Index(D:D,Match(A2,C:C,0),1)

then

say you are doing this in E2

E2:  =$B2-INDEX($D:$D,MATCH($A2,$C:$C,0),1)
you can then select E2 and drag fill (or copy and paste) it down column E.

Now if you don't get a match, the result would be #N/A.  you can avoid that with

E2: =if(iserror($B2-INDEX($D:$D,MATCH($A2,$C:$C,0),1)),$B2,$B2-INDEX($D:$D,MATCH($A2,$C:$C,0),1))

does that answer the question?  This assumes only one or zero matches in column C.  

--
Regards,
Tom Ogilvy  
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tom Ogilvy

Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 About.com. All rights reserved.