Excel matching or move to next matc - excel

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.

Related

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.

Does excel have an if statement equivelent? I can't get this program to work

The program has 5 columns.
Column A has item names
Column B has item sizes
Column C has item quantities
Column D has items that i need
Column E has the sizes for those items in the rows corresponding to the items
Most items do not have multiple sizes, but for the ones that do, there will be multiple entries of that item in column A.
What I need to do is take all the items from column D and find them in column A and give me the corresponding quantity from C.
I have been using this code to achieve this. =INDEX(C:C,MATCH(D:D,A:A,0))
This works for all items besides the ones with multiple sizes. For these items it just spits back the first size number every time.
Would there be a way to match A and D, and then check if there is a value in the size column, if so, give out the correct number?
I see how my wording is confusing here is an example of what I mean.
apples 5lb bag 12 apples 10lb bag
apples 10lb bag 13
bananas 5 grapes
grapes 7
Which using the is line of code "=INDEX(C:C,MATCH(D:D,A:A,0)) " would result in giving me the correct "7" for the grapes, but for the apples, it would give me the first result it comes across, which is the 12.
How would I get it to check the other columns to give me the 13 for apples?
If I understand correctly then this will get you the correct number:
=IF(E2<>"",SUMIFS(C:C,A:A,D2,B:B,E2),SUMIFS(C:C,A:A,D2))

Excel counting pairs

I have 5000 rows. In column A I have the salesperson , in column B the buyer. I am trying to find out how many times each combination appear together. e.g. Did salesman Abe sell to Buyer Bob 33 times, to buyer Carl 19?
ok takes a few extra columns to accomplish this but here goes...screenshot attached first.
First you need to concatenate the two columns (A and B)you want to enumerate in column C (the formula will accommodate a string in case names column is first last with spaces etc.)
=$A2&" "&$B2
Then in column D use the following formula to determine whether or not the name combination is duplicated but only true for one instance. I'll explain why in a second.
=$C1<>$C2
Then in column E count the matches.
=COUNTIF($C:$C,$C2)
After doing all that, filter results by "True" tally for all the True columns is the number of matching rep/customer relationships.

Excel Column Sorting

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

Microsoft Excel Referencing data

I am trying to figure out how to look up a cell to see if it contains a name from a list I have specified, we will use "Hofmann Trucking" for example.
Using columns a,b and c where column a contains average hours it takes for truck to travel from point a to point b, column b contains the carrier information (Hofmann Trucking) and finally column c which is where I would like the answer to go.
I want column c to return the time listed in column a, only if Hofmann trucking is the carrier in column b. If another carrier is listed I would like to put that information in column d.
In the end these times will be averaged per carrier per day so I can easily show how much time is spent traveling to and from certain areas by different companies.
This should do it:
Col A Col B Col C Col D
8 Hoffman Trucking =If(B1="Hoffman Trucking",A1,0) =A1-C1
Put those 2 formulas in columns C & D and drag down...

Resources