Pull cell data while other cells within row match a string - excel

I'm using google sheets for a work project, and I'm trying to pull data from a cell that is in a row with 2 cells that match what I'm looking for.
For example: I have 8 columns and 5600 rows in sheet 2. I want to pull the data from column "D" but only if the data in columns "A" & "C" match what I'm looking for. Say column "A" is filled with days of the week, and column "C" is filled with first names, and column "D" is filled with an ID number. I want the ID number from column "D", but only from the rows in which column "A" = "Thursday" & column "C" = "Jeff". There will also be some rows that share columns "A" & "C", but have a different number in column "D", and I would like to pull those as well.
Here is my attempt where I was able to grab the day of the week:
=INDEX('sheet2'!A:A,MATCH((INDIRECT("RC[-5]",0)),'sheet2'!C:C,0),)
(the indirect function is there because the first name I want to match for is always going to be 5 cells to the left of where this function is)
And here is my attempt where I was able to grab the ID number:
=INDEX('sheet2'!D:D,MATCH((INDIRECT("RC[-5]",0)),'sheet2'!C:C,0),)
So, I want to be able to call the second function above, but only if the first function evaluates to "Thursday", for example.

To me this boils down to two different problems
Q1) A multiple criteria lookup (INDEX+MATCH)
Q2) Returning several values when multiple rows match your criteria
Assume that the weekday is 6 cells to the left of your function and the first name 5 cells to the left. I have also restricted the range from searching the whole column. Adjust as needed, but the complete column is a bit too much for Excel to handle.
A1) This simple lookup will deal with the multiple critera issue, but doesn't fetch duplicates of the name and weekday combination.
=INDEX(sheet2!D2:D12,MATCH((INDIRECT("RC[-6]",0)&INDIRECT("RC[-5]",0)),sheet2!A2:A12&sheet2!C2:C12,0))
A2) This formula would list all the results in the same cells delimited by a comma, looking like this "121208,445555,445553", not on separate rows.
=TEXTJOIN(",",TRUE,(IF((INDIRECT("RC[-6]",0)=sheet2!$A$2:$A$12)*(INDIRECT("RC[-5]",0)=sheet2!$C$2:$C$12)*(1-ISBLANK(sheet2!$D$2:$D$12)),sheet2!$D$2:$D$12,"")))
Edit after comment feedback: Some versions of excel requires you to apply this formula with Ctrl+Shift+Enter instead of just Enter for it to work properly.
If you need to have all the matches for a pair of criterias stacked on separate rows I would recommmend that you check out the Power Query tool (native in the latest versions of Excel). This would be a relatively easy task for PQ to handle by merging tables with join kind "Left Outer".

Related

How to compare each cell with each other in MS Excel?

In large dataset - 250 rows and 1000 columns I need to compare each value in cell with each other in one column and iterate over all column. Heres simplified example of source data:
And this is what I need (formatting not necessary and 2 empty rows not necessary) - if match if found "1" is produced, if no match "2" is produced, if one or both were N/A - "3" is produced:
Comparison should only be "one sided" for example Terry and Joey is the same as Joey and Terry, thus further comparison of already compared pairs is not needed.
Is it possible to do this in Excel 2016 or are there better tools for this?
My thanks to all.
This alternative is a bit complex, but we all solve problems like this differently. If it helps you, please feel free to use it. If not, I can understand since some of these techniques are not particularly common and the resulting formula is a bit unreadable. I did it this way so that I would be able to organize the rows better and read the matching/unmatching indicators more easily. I started by creating a helper column rather than repeat the rows for each individual so that each row shows the two names being compared. This is the formula I used to compare using B8's information is:
=IF(OR(INDIRECT("R"&MATCH($I8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)="N/A",INDIRECT("R"&MATCH($A8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)="N/A"),3,IF(INDIRECT("R"&MATCH($I8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)<>INDIRECT("R"&MATCH($A8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE),2,1))
I am going to try to explain the formula I used as follows:
Without using the helper column, the basic formula for cell B8 is this:
=IF(OR(B$2="N/A",B3="N/A"),3,IF(B$2<>B3,2,1))
and this would work for the range B8:H11. However, when I skip down to B13, the formula would need to change to:
=IF(OR(B$3="N/A",B4="N/A"),3,IF(B$3<>B4,2,1))
and this would work for the range B13:H15. Likewise B17, and B20 would be:
=IF(OR(B$4="N/A",B5="N/A"),3,IF(B$4<>B5,2,1))
=IF(OR(B$5="N/A",B6="N/A"),3,IF(B$5<>B6,2,1))
for their respective ranges. I shy away from formulas where I have to remember what I need to change for each section (heaven forbid I should write any notes or read them if I did).
In order to do this, I used the person column (A) and my helper column (I) to determine which rows to compare.
MATCH($I8,$A$1:$A$6,0)
gives the row of the person value in the Chart from A1:H6 in the comparison
MATCH($A8,$A$1:$A$6,0)
gives the row of the helper value in the Chart from A1:H6 in the comparison
Since the data being compared is always in the same column, I just use COLUMN() to determine which column to use.
In cell B8, MATCH($I8,$A$1:$A$6,0) will tell me it is row 2 and MATCH($A8,$A$1:$A$6,0) will tell me it is row 3. Thus, I want to use the values in Row 2, Column 2 compared against Row 3, Column 2.
To tell Excel to compare Row 2, Column 2 against Row 3, Column 2 is fairly simple, but creating a formula that you can copy from cell to cell without having to modify it each time is not as easy, since each section is a bit different and there could be blank rows in between sections. What I did was to use indirect cell notation using "R1C1" syntax rather than the more common "A1" cell referencing.
In other words in column B8 this:
INDIRECT("R"&MATCH($I8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)
gives the value in Row 2 (for Terry), Column 2 and
INDIRECT("R"&MATCH($A8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)
gives the value in Row 3 (for Joey), Column 2 and
In both of the above, I am concatenating and R and a C to the numbers returned by the MATCH() and COLUMN() functions and using the FALSE parameter to tell Excel to treat the concatenated result as "R1C1" notation. In other words, this:
OR(INDIRECT("R"&MATCH($I8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)="N/A",INDIRECT("R"&MATCH($A8,$A$1:$A$6,0)&"C"&COLUMN(),FALSE)="N/A")
translates to this:
OR(R2C2="N/A",R3C2="N/A")
I realize that the helper column is a burden you did not ask for and I realize that the formula is overly complicated, but I can freely copy this formula to any column that has the two names and it will do a comparison for that day of the week.
Here is a picture of what I am describing:
Added comments
Just to carry the above a bit further, suppose you had a Sheet1 which had the rows of data to be compared and suppose this were limited to 250 rows with the same 7 columns (rather than 1000). I could create another sheet similar to the above along with another helper cell (I put it in A1) to automatically populate the person column and the helper column like this:
New Helper Cell value: 1 (essentially saying to start at the top). This would populate Cell A2 with the following formula:
=IFERROR(IF(INDEX(Sheet1!$A$1:$A$250,NUMBERVALUE(RIGHT($A$1,3)+ROW()))=0,"",INDEX(Sheet1!$A$1:$A$250,NUMBERVALUE(RIGHT($A$1,3)+ROW()))),"")
Basically this is just this formula:
=INDEX(Sheet1!$A$1:$A$250,NUMBERVALUE(RIGHT($A$1,3)+ROW()))
but is checking first to see if it results in zero and then is replacing it with blanks if it is an error. Copying this cell down Column A will populate that column with the names starting at the first row after the data row specified by A. If you have more headings or other data you would need to add additional amountst to the +ROW() portion in both occurrences in the formula. Column I gets populated siimilarly with this:
=IF(A2="","",INDEX(Sheet1!$A$1:$A$250,NUMBERVALUE(LEFT($A$1,3)+1)))
However, this value does not vary from row to row.
Now that the helper columns are populated, you can populate the formula a bit differently from the above (which had used the same sheet) for example in B2:
=IF($A2="","",IF(OR(INDIRECT("Sheet1!R"&MATCH($I2,Sheet1!$A$1:$A$250,0)&"C"&COLUMN(),FALSE)="N/A",INDIRECT("Sheet1!R"&MATCH($A2,Sheet1!$A$1:$A$250,0)&"C"&COLUMN(),FALSE)="N/A"),3,IF(INDIRECT("Sheet1!R"&MATCH($I2,Sheet1!$A$1:$A$250,0)&"C"&COLUMN(),FALSE)<>INDIRECT("Sheet1!R"&MATCH($A2,Sheet1!$A$1:$A$250,0)&"C"&COLUMN(),FALSE),2,1)))
The main difference from the first formula is the off sheet references to "Sheet1" that were added and the extension of the formula to cover 250 rows.
Here is a picture with Cell A1 set to 1:
Here is a picture with Cell A1 set to 3:
Using this, your Sheet1 values remain where they are and you can create a generic comparison sheet to compare the values of various rows of Sheet1. These can be dynamically built by changing the value in A1 or you can create dozens of similar sheets, each differing by the value in A1.
Not sure if any of this makes sense.
Good Luck
Just use a function like this(exemple for cell B4):
=IF(B3=B2;1;IF(B3="N/A";3;2))
Print of it working
Do it for each line and just drag it from the begining to the end.
EDIT: You should do an or in the 2nd if to make surre neither is "N/A"
=IF(OR(B3="N/A";B2="N/A";3;IF(B3=B2);1;2))

How to arrange small size of excel rows (subset) according to large size of other excel rows?

I have excel sheet with 500 rows and more than 10 columns. The first column is subject id.
And I have list of subject id approximately contains 2000 id. The 500 id in the spreadsheet is subset of the external 2000 id.
I want to arrange the spreadsheet rows according to the external list of ids.
Edit:
I have spreadsheet 'A' of 500 rows
and spreadsheet 'B' with 5000 rows
I want to edit spreadsheet 'A' by place its rows at the same position (row number) of its occurrence in 'B'.
In other words, you can see from above pictures that:
First subject of 'A' '2196978' is located in row number 2 in 'B'. My task is to put '2196978' of 'A' in row number 2
Second subject of 'A' '2219364' is located in row number 9 in 'B'. My task is to put '2219364' of 'A' in row number 9
and this is done by insert rows in 'A' if the subject of 'B' is not exist in 'A'.
This result is what I want:
Without resorting to Macros I don't think what you want to achieve is possible, however it is possible to get something very close. The core issue is that a function cannot create rows so you have to start with the number you want to end up with.
I my proposal you end up with a 3 Book solution. Book A with 500 rows, Book B with 2,000 rows, and Book C which is the result also with 2,000 rows but many of them blank.
You would start by creating Book C with a complete list of IDs from Book B i.e. all 2,000 of them. This could be a copy and paste or you could assign them using the Excel = function. For this example put them into column "A".
Next we want data to appear only if it is in Book A. We do the lookup using VLOOKUP() and if the data is missing we get a #N/A error.
So before things get complex in column B of the new Book add the formula:
=IF(ISNA(VLOOKUP(A1,[BookA]Sheet1!$A$1:$A$200,1,FALSE)),"row missing","row there")
This will return a text message indicating if the row exists in Book A and will be used as a flag to display the remainder of the data.
Check this works and if it does change it to:
=IF(ISNA(VLOOKUP(A1,[BookA]Sheet1!$A$1:$A$200,1,FALSE)),FALSE,TRUE)
We now want to get column B, C, D etc. from Book A based upon the True/False flag we have created. So column C in the new sheet is something like:
=IF($B1,[BookA]Sheet1!B1,"")
If you have the $ signs in the right places is should copy and paste nicely.
You have 2 options for improving this and getting nearer your objective.
Embed the initial lookup in the 2nd IF statement
Use conditional formatting to turn the text white if it should not be there (including the ID)
I have not done either of these because it is un-readable and is basically write once code that you can never modify without starting again.
Good luck.
You have to use the below formula in spreadsheet B which contains 5000 rows,
=IFERROR(INDEX(SheetA!$A:$J,MATCH($A2,SheetA!$A:$A,0),COLUMN()),"")
This is a simple INDEX - MATCH formula which looks up values in SheetA matches it with SheetB and prints output in SheetB. Use the formula in SheetB cell B2.
Explanation:
A2 cell in SheetB is matched with A:A in SheetA.
If found, pulls all the column data of that item from A:J from SheetA.
Once you pasted the formula in B2, drag it across all required columns. Then drag the same across all rows or just double click the fill handle, so that the formula is filled for all 5000 rows and data is pulled.
Let me know if you face any difficulties. Hope this helps.

Conditional formatting row referencing cells in another row

I'm creating a list, and wish to link items in that list...
Here's a hypothetical setup to relay the basic issue:
column B is merely a list of successive numbers (1 through 1000)
column K receives a value of "O" or "C" depending on whether the issue is open or closed
column L receives a numerical value that references the value of column B in another row.
I want column L to link one row to another.
ex:
Value of B1 is "1" --->we'll call this "row 1"
Value of B2 is "2" --->we'll call this "row 2"
If L2 is "1", I want row 2 to be linked to row 1.
Then, if K1 is "O", I want no action to be applied to row 2.
However, if K1 is "C", I want row 2 to be highlighted.
Essentially, we're creating finish to start links for tasks.
Therefore, this should be able to have several rows with column L values all referencing the same column B value, so when that row is changed to closed/"C", those several other rows all become highlighted.
I've been digging for a while, so sincerely appreciate the help.
You may try something like this...
Highlight the whole columns say B:L and make a New Rule for conditional formatting using the formula given below and set the format as per your choice.
=INDEX($K:$K,MATCH($L1,$B:$B,0))="C"
See if this is what you are trying to achieve.

How do I compare rows across sheets in Excel?

I've read through some of the topics that were similar to mine but I couldn't find an answer for what I need. Perhaps it is a logic problem on my part.
I have two sheets with identical data however they come from two different sources. I need to compare rows from 1 sheet to rows of the 2nd sheet to find out what is missing or different so I can fix.
I have columns A - M which has the data points. I then have column N which I concatenated all the columns together and compared them to other sheet doing the same thing so I could find the Non-matching. Out of 40,000 records I have 6100 that do not match.
What I am trying to do is compare the whole row (or the concatenated) and find out what value is different between the two. I was attempting to do this by IF with a VLookup and nested IFs but this didn't turn out correct because I wasn't getting it to compare the same value from the same Row plus I ran out of allotted nesting space. I was thinking a match,index system might work. I need some help!
Edit:
To be more clear the rows do not line up. What I have to do is make sure all the rows from sheet "1" are in sheet "2" but not all of sheet "2" need to be in "1". Basically I need this -
From sheet "1" find the value in cell A1 in sheet "2" A:A. Then match B1-N1 to that same row (whatever row it is). If possible I'd like to identify either by highlighting or having a word such as "Mismatch"
I usually create a new sheet and in use each cell to do a cell by cell comparison across the sheets. i.e. in new sheet cell a1 put =value(Sheet1!A1=Sheet2!A1) That give you a 1 where they're the same and a zero where they differ.
If you want you can set the column n on an original sheet to be the sum of the same row on the new sheet for easy reference.
I would use a VBA solution. If the number of rows are the same for each sheet and you are comparing row 1 with row 1, etc. then:
1) Loop through each row and concatenate the rows' cells for each sheet.
2) Apply the clean and trim function to the results.
3) Compare the results.
4) If they match, move to the next row.
5) If they don't match, loop through each cell of the row range to find the ones that differ and capture it somehow.
6) Print the results somewhere.
OR
Put the range values of each sheet into two arrays and compare the arrays (faster).
I'm certain there's a better way but that would be my approach, at least.

need the cound of Row C if the condition of Row A and B is match

IN row A i am having Date (Date might be today's date, yesterday’s date and day before yesterday's date)
In Row B i am having person name (Name Can be Arindam , Samir,Amit,Din
In Row C I am having the work status (Ctatus Can be Closed,Work in progress,Waiting,New
Now I want the Close Count status of Row C in Row D, but condition should be” if Row A is today's date and Row C is Arindam.”
Is it possible by excel formula?
Please help me out
This works for me, but there are a LOT better ways to organize your data (like with Tables and named Columns) that will make this kind of thing easier.
=IF(AND(A1=TODAY(), B1="Arindam"), C1, "")
You can "fill" that formula down the whole column D and the row number will auto-adjust. You might need to edit the A1/B1/C1 to match the row you actually paste this into (probably row 2 or greater, if you have a header row).
Op asked a follow-up that couldn't be easily answered in a comment.
From Excel help:
The COUNTIF function counts the number of cells within a range that
meet a single criterion that you specify.
COUNTIFS is a more complex variation of that.
For the original example given, the simple IF() above works correctly. COUNTIF is meant to count the NUMBER of cells (not to sum them) that meet certain criteria (like Date>Today, Count>3, or anything). There is a SUMIF that will sum up cells, but you didn't say you want to sum up cells, you said wanted the "Close Count status of Row C in Row D".
If instead you want a cell (not necessarily in column D, associated with the data in a single row) that "sums" up all of a given Close Count on a page, you could do this:
=SUMIFS(C:C,A:A,"="& TODAY(),B:B,"Arindam")
That's really great for a summary of ALL the rows of data, but it sounded like you wanted a summary per row, for which you should use the simpler IF() given above.
OK, one more update, now that I'm understand the original data better. This can be done in EACH row, and if you really want a total for the entire set of data, you'll have to have a total row (or separate sheet) that adds up column D:
=IF(AND(A1=TODAY(), B1="Arindam", C1="Closed"), 1, "")
This puts a "1" in column D if the criteria in columns A, B, and C match what you want.
If you want a single cell that sums up all the matches, then Jerry gave the correct answer (this is from him, and I think it's the best answer, although it was in the comments):
=COUNTIFS(A1:A10,TODAY(),B1:B10,"Arindam",C1:C10,"New")

Resources