Excel: Copy cell info based on string match from another sheet - excel

This is sort of a complex worded question, but I have created a sign-up sheet for my dorm's intramural teams, and the responses are listed on an Excel sheet with:
Sheet 1, cell B: Full Name
Sheet 1, cell C: Email Address
Sheet 1, cell E: The sports they wish to play on (there are four)
On sheet 2, I want to organize who and how many people want to play on each team. So I have a column for each sport, and under those are two columns (Full name and email address).
What I want to do is to parse through Sheet 1, cell E for each person who signed up, and if they have the instance of one of the four sports listed (Soccer, Dodgeball, Volleyball, or Bowling), add their Full name and email address under the correct column in sheet 2.
This is an image of sheet 2.
Is there a way/formula to be able to do this? Also, if the person signed up for multiple sports, they should be listed under each one. All the sports they want to play will be listed under a single cell (Sheet 1, cell E).

There is a way, with an array formula (entered with Ctrl+Shift+Enter)... In cell A3:
=IFERROR(INDEX(Sheet1!$B$1:$B$500,SMALL(IF(ISERROR(SEARCH(A$1,Sheet1!$E$1:$E$500)),9999,ROW(Sheet1!$A$1:$A$500)),ROW()-2)),"")
Let me explain from the inside out...
ISERROR(SEARCH(A$1,Sheet1!E10)) would give us FALSE if the value in E10 has the name of the sport (in our header cell: A$1), TRUE otherwise
Rather than just giving a single value, we are working on the array of cells Sheet1!$E$1:$E$500 (which could be extended as you needed) - so this gives us an array of TRUE and FALSE values
IF(ISERROR(...),9999,ROW(...)) means that if there was not the sport we will get the value 9999, otherwise we get the row number of the cell in the array - so this gives us an array of a mix of 9999 and row numbers
SMALL(...,ROW()-2) lets us pick out one of those values from the array - in this case the items in size order, and we are using ROW()-2 as our counter (i.e. in Sheet2!A3 - ROW()-2 is 1 and we get the smallest value from the array)... the -2 deals with the header rows... Effectively we are indexing through a sorted list of row numbers in Sheet1 that match our condition
INDEX(Sheet1!$B$1:$B$500,...) is going to give us the value from column B in Sheet1 relating to our position in the list of matching rows - i.e. the Name
Sometimes we have our 9999 (for all the cells that didn't match the condition - these are sorted to the end of the list with SMALL) and so the INDEX will give us an error... the index is outside the range. So we can replace it with a blank.
In cell B3 we would do the same, but with =IFERROR(INDEX(Sheet1!$C$1:$C$500,... so that we get the email... We still need to reference A$1 for the sport name. These two cells can then be copied across and down...
Hope this makes some sense! Good luck! And remember to enter array formulas with Ctrl+Shift+Enter...

Related

Return second (and subsequent) unique name in list

I have a list of data that I get from a third party. For simplicity, lets say that Column A is the Unique ID (alpha-numeric), and Column B is the employee who is assigned to that ID. One employee has several ID's, as they work several cases at a time. A few of the Unique ID's begin with "AC", and these ID's are special cases.
I need a formula that will search through Column A on the "Raw Data" sheet for any license number that begins with "AC", and return the Assigned Employee name on my "Assigned Employees" sheet. This is easy enough for the first one with a simple index match formula. However, I need it to bring back the second name, and any other names that are there. In the example below, I would need it to bring back Paul, then Lee.
Column A Column B
Unique ID Assigned Employee
AC798358 Paul
90807248 Paul
AC48298 Lee
B98281 Lee
AC42795 Lee
The table on "Assigned Employees" looks like this:
Employee 1 Employee 2 Employee 3 Employee 4
Paul Lee
I'm using this index match formula to get the first return (Paul), but it will only work for the first "AC" ID number on the sheet.
=INDEX('Assigned'!$B:$B,MATCH("AC*",'Assigned'!$A:$A,0))
I'm trying this formula, which would bring the first and subsequent returns by changing the "k" number for the "Small" function, but it's not working for me.
=INDEX('Assigned'!$B:$B,SMALL(IF('Assigned'!$A:$A="AC*",ROW('Assigned'!$A:$A)-ROW(INDEX('Assigned'!$A:$A,1,1))+1),1))
I know that it doesn't like this part: IF('Assigned'!$A:$A="AC*", but I don't know how else to write it to make it work. Any help would be appreciated.
Possibly relevant: there are a lot of blank rows in this data set.
There is a standard array formula method for pulling a unique list from a list of duplicates. For your sample data, put this in D2, finish with ctrl+shift+enter (aka CSE) then drag right.
=INDEX($B2:$B10, MATCH(0, COUNTIF($C2:C2, $B2:$B10), 0))
You can add conditions (e.g. IF(LEFT($A2:$A10, 2)="AC") to this.
=INDEX($B2:$B10, MATCH(0, IF(LEFT($A2:$A10, 2)="AC", COUNTIF($C2:C2, $B2:$B10)), 0))
This style of LISTUNIQUE formula requires an unused cell to the left (or above if listing into rows). If you don't have the room for an unused cell to the left or above, you could avoid that by using a more conventional formula to achieve the first item in the list and modifying the second to use the first as its reference starting point.
'in D2
=INDEX(B2:B10, MATCH("AC*", A2:A10, 0))
'in E2 (with CSE and dragged right)
=INDEX($B2:$B10, MATCH(0, IF(LEFT($A2:$A10, 2)="AC", COUNTIF($D2:D2, $B2:$B10)), 0))
You can avoid the #N/A errors when you run out of matching items with a wrapping IFERROR function.

How to transfer data between files?

In one spreadsheet I have a list of emails only. In another spreadsheet I have a list of the emails but also names, organizations, etc.
I have some background in programming but not with manipulating Excel. What I would like to do in terms of pseudocode is look at each email address on a new line in the first document, test IF the second document has that email, and if so retrieve first, last name, organization, etc. from the second document, and paste it in the appropriate columns in the first column. If not, to highlight the entire row in green in the first document.
Is this possible? Your help is greatly appreciated!
This can be accomplished a couple of different ways, the easiest would be a vlookup(), but a caveat with respect to vlookup() and the arrangement of the sheet 2 Data: Anything you would return from sheet 2 must be to the right of your lookup value (email address in your case). Vlookup() will not return anything to the left.
Also, Excel cells don't put into other cells, but receive a value into the current cell. (Yes, you could write a VBA function to put a value into a cell, but that may be advanced considering your experience 'manipulating Excel')
Assuming your sheet 2:
A B C
John#xyz.com John Smith Big Company
And Sheet 1:
A B
John#xyz.com
Your psuedocode in sheet 1 would be:
vlookup(from col a, in sheet2 -columns A(1) thru C(last row), return the nth column, False - I want an exact match)
The vlookup expression is:
(again in Sheet 1 Col B -- return the company name
=vlookup(a1,sheet2!a1:c1,3, 0)
Here 3 refers to the 3rd column of sheet2.
If you need more information:
GOOGLE:
vlookup()
hlookup()
index(match())
This is normally handled using the vlookup() function. So you'd use the email from book1 as the lookup_value, the range containing the values in book 2 as the table_array, the column from book 2 containing the value you want to import as the col_index_num (so if book 2 has email, name, organization in that order, you'd use 2 to pull in the name), and false as the range_lookup argument, to get an exact match. Something like
+VLOOKUP(A1,[Book2.xlsm]Sheet1!$A$1:$B$3,2,FALSE)
This will leave a #N/A in cells that don't have a matching email in book 2. You could use conditional formatting to turn the row green by saying "Use a formula to determine which cells to format" and using =isna($b$1) as the formula for example.

VLOOKUP or INDEX-MATCH for text from bottom to the top with reference to another sheet in the workbook

I am making a log for work and in one of the columns, I need a formula that fills each cell with the latest text information from another sheet in the same workbook. I have attached a picture of the worksheet I am working in and a picture of the referenced worksheet.
The worksheet I need the formula in
The worksheet with the reference cells
In image 1, there are 2 column titles highlighted. Column 'A' and Column 'S'. Column A is the id of one of my animals, and column S is supposed to have a date/initial in there for my macro to work. However, people forget to fill it in and only fill it in the sheet from image 2 in Column 'P'. Because we reuse the same animal more than once the information that goes into column S in the first image always needs to be the newest information from the reference sheet. I know how to do a VLOOKUP with the dates, I have already done those, but because I need the cell to populate with text instead of numerical values, I am having trouble.
I will list some formulas I have tried that are supposed to go from the bottom to the top but don't work and maybe just need to tweak and some that work if I was going from the top to the bottom.
Formulas that don't work going from the bottom to the top but I'd think would:
=LOOKUP(2,1/(FIND(A18,BREEDING!D:D)),P:P)
=INDEX(BREEDING!P:P,MATCH(A21,BREEDING!D:D,0))
=LOOKUP(2,1/(BREEDING!D:D=A21),BREEDING:P:P)
Formulas that do work but go from the top to the bottom:
=(VLOOKUP(A17,BREEDING!D:Q,13,FALSE))
References:
Column A: Animal ID that is present in the 1st image
Column D: Animal ID that is present in the 2nd image
Column S: 'Date Weaned' cell that will contain the formula and information from the 2nd image should populate into
Column P: The actual date weaned that should go into column S of the 1st image
TL;DR
In image 1, cells in column S should have the latest text information from column P of image 2 if the information from Column A of image 1 matches the information from Column D of image 2
Formula that you could use is below
=INDEX(BREEDING!P:P;AGGREGATE(14;6;ROW(BREEDING!D:D)/(BREEDING!D:D=A2);1))
how it works - the index is simple, the aggregate the is main thing - it uses 14 as first parameter which is function LARGE (return k-th largest value) and then the 6 is the most important, because that means "skip errors". This is vital, because when you divide by (BREEDING!D:D=A2) it divides by 0 or 1 based on false/true so creates lot of errors and keeps only the lines with Animal ID equal to Animal ID of the line. Then it uses LARGE function on all lines with that Animal ID and because of the last part ";1))" it returns the highest row number where the Animal ID matches. This way you should be able to get the value from your second sheet for the newest (highest row number) line.
The formula can be quite resource-intensive so you might have to repaste as values - if you are periodically running a macro on the data you can have it also apply the formula and then change to values if it gets too long to calculate every time you want to change something...

OFFSET / INDIRECT function trouble

I have two sheets within a workbook, the first with several thousand lines of expenses, separated by individuals, and the second a summary of totals and such.
On the second sheet, I've created a reference to the first to insert each individual's name (i.e. B4: ='Card Transactions'!D89). I'm having difficulty with the syntax for returning the total of each individual's total, which is in a predictable cell in the first sheet relative to the name (down 1, right 7).
I've tried the following:
=offset(indirect(B4),1,7) with only a reference error in return. This seems like it should be relatively simple but I'm not having any luck. . . any suggestions?
use this:
=OFFSET(INDIRECT(MID(FORMULATEXT(B4),2,300)),1,7)
note:
this only works if the formula in B4 only contains the one cell reference.
This is a volatile function and will cause a noticeable lag in calculations if used too many times.
The following should work for you as long as your data follows these rules:
Your columns have headers
The names are all in the same column
And you are able to set the range with row numbers and not just full columns
Let's say your first sheet is set out like this:
And you want your second sheet like this:
And your sheets are named:
Sheet1
Sheet2
This is the formula in B2 of Sheet2:
=INDEX(Sheet1!$A$1:$H$9,MATCH(A1,Sheet1!$A$1:$A$9,0)+1,MATCH("Column 8",Sheet1!$A$1:$H$1,0))
And here's what it does:
Your index array is the entire blue area, this can be the whole sheet but can't be a full column reference, the row number must be specified. In this example, the index array is $A$1:$H$9 and the $ signs mean the range won't move when you drag down the formula, so they are important!
Your first match finds the row number, it uses the name (in this case 'bart') as the lookup value, and the purple area as the array. In this example the row array is $A$1:$A$9 and the row numbers must match the row numbers in the index array. The match has a "+1" at the end, so it will find the matching row, then add one row down to get your offset.
Your second match finds the column number, it will need to use the name of your column. In this example the column array is $A$1:$H$1 and the column letters must match the column letters in the index array.
Let me know if this doesn't fit your problem, I'm sure we can figure it out.
Thanks.

formula to search rows then allocate specific name from another table

I have a spreadsheet that is pulling in call survey data and set up as follows
Main sheet is called 'Data'
In the main sheet, columns F,G,H,I hold agent ID numbers dependant on what agents worked on this specific call through it's journey to end. All agent numbers start with the prefix either of 146,144 or 145.
so for example 1st agent 14400 took the call then transferred to agent 14600 then that one onto agent 14500.
Sheet 2 is called 'Teams'
Column A holds agent ID's
Column B is team name
What i want to be able to put a formula in column A of the sheet 'Data' which will then search through rows until it finds a number begining 146.
Once it has found this number it will then search the sheet 'teams' and allocate the required team manager name from column C.
Hope this all makes sense but please let me know if not.
Thanks
This is the solution (I tested it on your spreadsheet):
=VLOOKUP(SUMPRODUCT(--(F2:I2>=146000),--(F2:I2<=146999),F2:I2),Teams!A:C,3,FALSE)
--(F2:I2>=146000) return an array with 0 or 1, 1 if the value is greater than 146000, --(F2:I2<=146999) same but 1 if value less than 146999
SUMPRODUCT is a logical and between the three array that return the value 146xxx. to know more sumproduct
VLOOKUP search in the first column of the range A:C on the Teams' sheet for the id and return the content of the third column.
If you want to have a custom result if the 146xxx is not present in the row you have to use IFERROR(VLOOKUP(..),"TEXT_TO_SHOW")

Resources