Excel Column Sorting - excel

Im using Excel 2010... This problem has been plaguing me for hours and would save me a lot of time, I have really tried searching for the answer but dont know what I am looking for without explaining in detail.
Basically I have 5 columns of data. Column A contains a list of selected names, Column B contains a list of all names and Columns C to E contain data relating to all names:
A B C D E
steve adam 54 london car
doug andrew 25 essex walk
adam bert 31 newcastle walk
omar barry 47 london car
chuck 23 herts cycle
(columns continue)
I need to be able to sort the data so that the names in column A are in order and the other data in columns B to E match what is in column A with any non matches at the bottom of each list. So the result would look like:
A B C D E
adam adam 54 london car
doug doug 37 norfolk walk
omar omar 31 dudley jog
steve steve 74 london cycle
andrew 25 essex walk
(columns continue)
In real terms I have a list of thousands of names and need to match hundreds of names to them. If any one can help with this it would save me hours of work. I have tried searching and have watched many youtube vids on vlookup but nothing seems to be specific to what im after.
Thanks in advance
George

Excel might not be the best tool for the job but try this:
Order column A by itself
In cell F1, use this formula: =IFERROR(VLOOKUP(B1, A$1:A$4,1,FALSE), CHAR(142)). Replace the "4" in A$4 with the number of your last row of data (in both columns A and B).
Copy that down column F to the last row of data. You will see a Ž in rows where there isn't a match between A and B.
Select the data in columns B to F (leave A out) and sort using columns F as the first level and B as the second level (a single sort operation).
The data in A and B should align with the extra rows in B at the end.
If it doesn't align it means you have values in A that are not in B. Select the values in F, copy and paste special (values only) over the values in A. Delete all the Žs from the end.
Delete column F

Related

Sum values using lookup table, where lookup values are a list of values with comma delimiter

I am trying to sum values based that equal a lookup value. However, that value is actually a list of values delimited by a comma. Below is an example of what I mean.
Suppose I have raw data in the form of sheet1 below:
Sheet1:
A
B
1
ID
VALUE
2
A
30
3
A
50
4
A
20
5
B
10
6
B
20
7
C
70
8
C
40
9
D
30
10
E
50
11
F
20
12
F
30
13
G
10
And I have a look table that groups all IDs by their respective teams, as per sheet2 below.
Sheet2:
A
B
1
TEAM
IDS
2
Red
A, B
3
Blue
C, D
4
Green
E, F, G
And I want to create a report where the user can select the team name, and the sum of the values in sheet1 will aggregate based on the selection, as per the following example. So the user would select "Green" in cell B1 and it would return the sum of values that correspond to E, F, and G in sheet1.
Report:
A
B
1
Select Team:
Green
2
Sum:
110
I have searched all over for a solution to this and was able to find something similar. I tried to repurpose the formula for my data but couldn't get it to work because I think that solution dealt with numbers rather than text.
Excel: Perform a SUMIF where the criteria is a comma-delimited list
Any suggestions would be greatly appreciated!
Edit: Just want to add that I realize I could first parse out the IDs in sheet2, however I'm looking for a formula that can bypass that as my real dataset is quite large and parsing out the IDs under each team would explode the number of rows.
A variation of #JvdV solution on the linked question:
=SUMPRODUCT(SUMIFS(Sheet1!B:B,Sheet1!A:A,FILTERXML("<t><s>"&SUBSTITUTE(VLOOKUP(Sheet2!F1,Sheet2!A:B,2,FALSE),",","</s><s>")&"</s></t>","//s")))
Note, this only works with Excel 2013 or later and only on PC. FILTERXML is not available on Mac or prior to 2013.
If Mac or prior to 2013:
=SUMPRODUCT(SUMIFS(Sheet1!B:B,Sheet1!A:A,TRIM(MID(SUBSTITUTE(VLOOKUP(F1,Sheet2!A:B,2,FALSE),",",REPT(" ",999)),(ROW($ZY1:INDEX($ZY:$ZY,LEN(VLOOKUP(F1,Sheet2!A:B,2,FALSE))-LEN(SUBSTITUTE(VLOOKUP(F1,Sheet2!A:B,2,FALSE),",",""))+1))-1)*999+1,999))))

Distributing students across classes based on marks

Name
Marks
Rank
Class
Eddie
20
6
C
Tom
10
10
A
Jenny
30
4
A
Riva
40
3
C
Andy
50
2
B
Mark
5
11
B
Sally
78
1
A
Jack
15
8
B
Dick
15
8
C
Harry
20
6
A
Dom
30
4
B
The students are expected to be distributed across classes A, B and C, based on their marks in the above picture.
The student with the highest marks goes in A. The one with the next highest goes in B. The next highest goes in C. The next goes again to A and so on.
What should be the formula to be used in Excel 2013 and above for calculating the Class?
Sort the table by either Marks descending or Rank ascending.
D2: =CHOOSE(MOD(ROWS($1:1)-1,3)+1,"A","B","C")
If you are using Excel 365, you can use the SORTBY function to solve the question.
Assume the Name column is in a named range called List_Name, the Marks column is in a named range called List_Marks, your example dataset is in range A1:D12, and you want to return the class code in column D.
In cell D2, enter any one of the following formulas and drag it down:
=CHOOSE(MOD(MATCH(A2,SORTBY(List_Name,List_Marks,-1),0),3)+1,"C","A","B")
Alternatively, you can use the following in cell D2 instead:
=INDEX({"C";"A";"B"},MOD(MATCH(A2,SORTBY(List_Name,List_Marks,-1),0),3)+1)
If you cannot use the SORTBY function, then the answer provided by Ron Rosenfeld should do the job quite well.
Let me know if you have any questions.
Assuming that the chart you provided is in cells A1-D11
Try making a 2x3 chart on the side (I’m using F2-G4 with 1...A 2...B 0...C
and then put the formula in D1 as follows: =vlookup(mod(C2,3),F2:G4, false)
You could even skip out the whole C column if you wanted, writing =vlookup(mod(rank(A2,B:B),3),F2:G4, false)
But then you might have an issue of 2 people going to the same class if they rank the same.

Pick multiple values from list and ignore empty cells

I have the following Excel spreadsheet:
A B C D E F G
1 USER1 USER2 MICHAEL SANDRA JAMES CAITLIN
2 Product A Michael James Michael James
3 Product B Sandra Caitlin Sandra Caitlin
4 Product C James Caitlin James Caitlin
5 Product D Michael Sandra Michael Sandra
In Columns D:G 4 users of a product are listed. If a product is used by a User his/her name appears in Cells D2:G5. If he/she does not use the product the cell remains empty.
In Columns B:C I want to achieve now that the emtpy cells are eliminated and the maximum 2 Users are listed.
Do you know any formula that can go through the Cells D2:G5 to pick the 2 Users and show them in Columns B:C?
I don't know of any quick formula that you can use.
You are probably best off using VBA. You could write something compact and concise in there. VBA is definitely the way to go if your matrix is going to grow in size.
However, if you insist on doing it in Excel with available formulas, AND the matrix remains relatively small, here is one way to do it:
You will need column H and I for "Mask" information. You can hide these columns in the finished worksheet.
A B C D E F G H I
1 USER1 USER2 MICHAEL SANDRA JAMES CAITLIN MASK1 MASK2
2 Product A Michael James Michael James 1010 10
3 Product B Sandra Caitlin Sandra Caitlin 101 1
4 Product C James Caitlin James Caitlin 11 1
5 Product D Michael Sandra Michael Sandra 1100 100
In cell H2, You can create the first Mask:
=IF(D2 <> "",1000,0)+IF(E2 <> "",100,0)+IF(F2 <> "",10,0)+IF(G2 <> "",1,0)
This is a positional Mask which puts a 1 in each numeral column where data exists.
In cell B2 for USER1, you can put the nested IF formula:
=IF(H2>=1000,D2,IF(H2>=100,E2,IF(H2>=10,F2,IF(H2>=1,G2,""))))
This uses the Mask to find the first occurrence of data and place it in the USER1 column.
Finding the second user is a little more tricky. But all we have to do is create a second Mask in column I. In cell I2 you can use this formula:
=IF(LEN(TEXT(H2,0))>1,VALUE(RIGHT(TEXT(H2,0),LEN(TEXT(H2,0))-1)),0)
Let me break that formula down for you. We want to convert the first Mask in H2 to text so that we can trim off the first character (which corresponds to USER1) because, we don't need USER1 data anymore. Using TEXT(H2,0)
=IF(LEN(TEXT(H2,0))>1,VALUE(RIGHT(TEXT(H2,0),LEN(TEXT(H2,0))-1)),0)
^^^^^^^^^^
But to do a right trim that removes the right most character, we need the length of the same text string minus 1. LEN(TEXT(H2,0))-1
=IF(LEN(TEXT(H2,0))>1,VALUE(RIGHT(TEXT(H2,0),LEN(TEXT(H2,0))-1)),0)
^^^^^^^^^^^^^^^^^
Using those in a RIGHT function gives us our new Mask which removes USER1.
=IF(LEN(TEXT(H2,0))>1,VALUE(RIGHT(TEXT(H2,0),LEN(TEXT(H2,0))-1)),0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
But we can't do math on a text string, so we have to convert it back to a number using the Value function.
=IF(LEN(TEXT(H2,0))>1,VALUE(RIGHT(TEXT(H2,0),LEN(TEXT(H2,0))-1)),0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
That's our new Second Mask that we can use to find USER2. However, we need to test for error values as well. If all the cells are blank, it will have an error since you can't have a length of 0 in a Right function. So we need to test if the length of the text is greater than 1. LEN(TEXT(H2,0))>1
=IF(LEN(TEXT(H2,0))>1,VALUE(RIGHT(TEXT(H2,0),LEN(TEXT(H2,0))-1)),0)
^^^^^^^^^^^^^^^^^
Encase that all in an If statement and you now have your new Mask for USER2.
Now it's a simple nested IF formula for cell C2 by using the Mask in cell I2:
=IF(I2>=100,E2,IF(I2>=10,F2,IF(I2>=1,G2,"")))
We were able the toss out the test for 1000 since we know that would have been caught for USER1.
Now just copy the cells B2, C2, H2, and I2 down three more rows and all of your data will appear.
You can hide columns H and I if you'd like.
So, all in all, it's not that difficult (if your matrix remains small). There are only 4 formulas needed to make this work. And they are only of moderate complexity.
But once again, if your matrix is eventually going to grow in size, it will definitely be better to write this all in VBA.
Hope this helped. :)
It is possible without a formula though might be a bit tedious without VBA or similar (though not tagged that way):
Insert enough extra columns between C and D to be able to copy all of D:G into C.
Copy what was D:G into C and move what was the content of D:G out of the way (to other rows or other sheet/book).
Select the populated rows in C:F (or equivalent), HOME > Editing > Find & Select, Go To Special..., Blanks (only) OK.
Right click one of the selected cells and Delete..., Shift Cells left, OK.
Copy what was D:G back to E2.
The chosen two will be those furthest to the left.

Comparing two columns in Excel

I have data with about 15 different columns and a total of 2400 rows.
The two columns I'm interested in: (Column C = Application Owner & Column D = Application Tester). I'm trying to see which rows have the same name for both columns.
E.g.
Column C =
Mike
Bob
John
Bob
Adam
Column D =
Mike
Barry
Barry
Barry
Adam
So for this example I would like it to delete the contents of the three middle rows and only show me the first and fifth row because that is what I'm concerned with. Can anyone suggest a function of code or a function in Excel in which I can do this without actually having to go through all of them row by row?
Thanks
Add a column with something like =C2=D2 copied down to suit, filter for FALSE in that column and delete rows.
In a new Columns you can use =if(C2=D2,"DELETE","") then filter out this new column for DELETE and delete the values from column C and D or the entire range

Excel matching or move to next matc

So I am trying to teach an introductory biology lab, if it was not for that this would be much easier, but for the students I have to keep things in two separate columns instead of one. Okay, with that said here is what I have and what I need:
first, each row is an individual male and female and the columns represent their "gene"
We have a female and male that are going to mate, so the respective genes (two copies for each male and female) have an A allele and a B allele, we are only concerned about the males. I need a function that 80% of the time the female will not "mate" with a male with two of the same copies (BB), and will move down to the next male. So the males' letters are in column C and D. It will randomly donate either the letter from C or D to the new offspring, we do this by setting columns F & G for the male
=if(rand()>0.5,C1,D1)
That goes into E and F columns. Now comes the part about fusing it with the female (in columns G and H, easy enough just concatenate them. But I need picky females that do not like males with a B in both the C and D column, and will 80 % of the time find a male that has either A in both C and D or has A in one and B in the other (doesn't matter which column they go into).
What I have so far:
=IF($C1="B"&$D1="B",if(rand()>0.2,concatenate($E1,$G1),???????)
so where I have the question marks I need something that finds the first male (i.e. row) where $C? & $D? are not "B" and then concatenate($E?,$G?).
Any help would be greatly appreciated. I just cannot figure out how to search and find the first row that meets those requirements. It is pretty much the searching part I cannot figure out, not the meeting the requirements.

Resources