IF statement that inserts text based on matching text - excel

I have a large table in excel that has column headings A, B, C, D, and ANSWER
A, B, C, D represent the multiple choice questions I have in the table.
I also have an ANSWER column that has the answers represented by the corresponding multiple choice heading letter mentioned above.
For example, under each column heading (A, B, C, D), I have the possible answers, Food, Car, House, School.
In the example above, House (C) is the correct answer. I would like to create an IF statement that matches the Answer cell, which has C in it with the A, B, C, D column headings and if there's a match, then insert an = before the actual answer. In this case, the result would be =house. The rest of the answers should have the ~ inserted before the word, i.e., ~food, ~car, ~school.
The final result should look like this: ~food, ~car, =house, ~school.

The only way to achieve that securely is to duplicate the table in another sheet or in different columns.
Why is that?
Because you want to change the SOURCE of your statement. Excel would consider that a circular reference and couldn't resolve it.
There's a VBA code solution, that you can run ONLY ONCE. That would change the source data as well and you would lose your originals. Could be an action with no turning back.
So:
I suggest you create a new sheet, put the headers A, B, C and D.
So you would have two sheets: the OriginalSheet containing the answers and each option.
And the ResultSheet, containing the options formated as you want.
In the ResultSheet, use this formula:
= IF(OriginalSheet!$E2 = A$1; "="; "~") & OriginalSheet!A2
That is considering the first line containig the texts: A, B, C and D. So you must insert this formula in the A2 cell of the ResultSheet.
You can click in the little black square in bottom right of the cell and drag this formula to all other cells. (The $ simbols garantee the drag will be safe)

Related

Search multiple columns for text contained within another column, return a value

I apologize if this is a silly question, or if it's been asked before, but I have searched all over and haven't found a similar question/solution. I need to look within two possible columns (A and B) for text contained in another column (E). If text contained in column A or B is found within column E, I need the value in column C to appear in column F.
The text in column A and B will not be identical to that in column E (if it were I wouldn't be asking this question). And there may or may not be data in column B (not sure if that adds any complexity, but just for clarity).
I've tried all sorts of combinations of INDEX(MATCH and ISNUMBER(SEARCH, etc. but to no avail. I'm pretty sure there is a simple solution for this. Any help would be greatly appreciated!
You can use following array formula:
{=INDEX(F$2:$F$6,MATCH(1,--(MMULT(--ISNUMBER(SEARCH(IF(ISBLANK(B2),A2,A2:B2),$E$2:$E$6)),TRANSPOSE(COLUMN(IF(ISBLANK(B2),A2,A2:B2))^0))>0),0))}
Array formula after editing is confirmed by pressing ctrl + shift + enter
EDIT:
Reverse search - from column C to column F. Also an array formula.
{=INDEX($C$2:$C$9,MATCH(1,--(MMULT(--ISNUMBER(SEARCH(IF(ISBLANK($A$2:$B$9), $A$2:$B$9 & "#",$A$2:$B$9),E2)),TRANSPOSE(COLUMN($A$1:$B$1)^0))>0),0))}
In the expression $A$2:$B$9 & "#" instead of # you can specify any character that is not used in the search text
Not sure if there is an easier way, but with some validation you can easily come up with something like
=IF(OR(IF(A3<>"",ISNUMBER(SEARCH(A3,E3)),FALSE),IF(B3<>"",ISNUMBER(SEARCH(B3,E3)),FALSE)),C3,F3)
It verify that both A3 and B3 are not empty (<>"",...,FALSE) and return false if so.
It than make twice the same validation for A3 and B3; Search if the cell is contained within the cell E3.
If any of the two above is TRUE, than the whole IF is true, and it will return C3 as you need.
You didn't mention what you required in the case that the string was not found, so in my exemple, it return the value in F3 (but you could replace it with whatever).
Hope this help!

Find Coincidences on a Matrix

I'm trying to create a formula for the following issue.
I have one sheet with two columns:
A Spare_part_code which are alphanumeric codes
B Part_type which is just a letter from A to E. (we assign the importance f a part based on the letter, being A most important and E less important)
Then on another sheet, I have a list of repairs, one per line that have in lines from G to X the parts used on that repair.
I would like to, per repair, have a formula that search among all the parts used on that repair, and return the level of the parts used, but only the Letter of the most important part, for example:
For repair XXXXX I have used 10 parts, and all of them are E type, except one which is B, so In this case I need to show B on the result
For repair YYYYY I have used 3 parts, all of them A, so I need the formula to return A.
Suppose this is the final output you needed.
Add this formula in cell F2 and Drag down. I have written the formula from column G to X as you have requested.
=IF(COUNTIF(G2:X2,"A"),"A",IF(COUNTIF(G2:X2,"B"),"B",IF(COUNTIF(G2:X2,"C"),"C",IF(COUNTIF(G2:X2,"D"),"D",IF(COUNTIF(G2:X2,"E"),"E","NA")))))

Formulas not working in excel when i put 58+2 instead of 60?

I want to put 58+2 instead of 60 in Microsoft Excel cells. But, when I do that the cell is not counted for summation or other functions. How do I put 58+2 in a cell and get results?
If I put =58+2 inside the cell, due to AUTOSUM it automatically turns to 60
enter image description here
You can solve this with a couple of helper columns (which you can then hide from view). I'll give you two options/examples
In the example titled 'From helper columns to display' In Columns C & D I keep the raw values of the marks and the bonus. Then in Column A I use the
formula
=C3&"+"&D3
To give my result. In column F I can then calculate totals etc. based on the columns C and D.
In the example titled 'From display to helper columnns' this assumes you already have the data stored as xx+x. In column C I use the formula
=VALUE(LEFT(A7, FIND("+",A7)-1))
And column D
=VALUE(RIGHT(A7, LEN(A7)-FIND("+",A7)))
To get the actual values. I can then again use these columns to calculate my totals etc.
The columns C & D can be hidden for visual purposes. Both of these scenarios will achieve the same result it just depends what the format of your data is currently in as to which one you would use
For any cell you want to calculate instead of hard-code, add an equals sign at the beginning
=58+2
will be evaluated by Excel to be a function rather than text and will evaluate it.

using if search formula in excel

is there a way to combine a search formula with a lookup or possibly use an if then statement. I think I have the first part working but need help with the second part. I am looking for values in column A and based on the values found in column A, I need to look at values in other columns and return the value found in that column.
Example, if column A contains value "car", I need to look at column B and return the value found in column B in column F , if column A contain value "boat", I need to look at column C and return the value found in column C in column F.
Any help would be much appreciated
Assuming that you have a list of possible values: car, boat, bike, plane, ... that would lead you to look for values in column B, C, D, E, ... I suggest you do the following:
Define the name "transportation" (whatever name you want to call it) with the types of transportation you need - for example, ={"car", "bike", "tram", "bus", "boat"} . On Office for Mac 2011 you do this with Insert->Name->Define... - for other versions of Excel it might be different (but note - you actually type both the = sign and the {} curly braces around the list of values you want to be able to look up). Put them in the order of the columns that you want.
For every lookup that you need, you can now write
=INDEX(B4:F4,0,MATCH(A4,transportation,0))
if the value (car, bus etc) is in cell A4, and you want to look up the corresponding value from columns B through F.
If you have column headings above your columns, you can use the MATCH function without having to define a name explicitly. For example, if you have car, bike, tram etc in cells B1:F1, you can use
=INDEX(B4:F4, 0, MATCH(A4, $B$1:$F$1, 0))
to do the lookup.
Explanation: the MATCH function (with third parameter 0) looks for the exact match for the first value (in cell A4 in this case) in the array that is the second parameter (either the named range, or the range with fixed address that I gave above). You then look up the appropriate cell using the INDEX function which gives you an offset into the range (B4:B4 in the above) of cells where you need to do the lookup.
I trust you can adapt this to your exact needs. Ask if you need more help.
The following formula is the simplest way I can think to do it:
In cell F1, the formula would be
=IF(A1="car",B1,C1)
This is case insensitive, so it should work for CAR as well. But bear in mind that this has the downside that with a formula this simple, ANY value in A1 other than "car" (not just "boat") would lead to the other value ending up in the F column.
=IF(A1="car",B1,IF(A1="boat",C1,""))

Boolean check in Excel, checking only first character

I have an Excel sheet with data only in the first column, where each cell starts with the character H, G, I, B, H, E, S, C, or none of the above.
I would like to write a command so that in the second column, one of four things will happen:
If the cell in the first column starts with H, G, or I, then the cell in the second column is assigned H
If the cell in the first column starts with B or E, then the cell in the second column is assigned E
If the cell in the first column starts with T, S, or C, then the cell in the second column is assigned C
If the cell in the first column starts with none of the above, then the cell in the second column remains blank
I found that this command does part of the problem:
=IF(OR(B25="H"; B25="G"; B25="I");"H";"") & IF(OR(B25="B"; B25="E");"E";"") & IF(OR(B25="T"; B25="S"; B25="C");"C";"")
However, this only works if the first column only contains one character. I would like to tailor this command so that it does not require there to only be one character in the first column, but that it simply starts with the character.
I hope this makes sense. Please let me know if you have any advice!! :O)
Maybe the "LEFT()"-Function is what you are looking for.
Something like "LEFT(A1,1)" should give you the first Character of the String in Cell A1.
More information:
http://office.microsoft.com/en-us/excel-help/left-leftb-functions-HP005209153.aspx
EDIT: Wow, this community is always impressing me. (Too fast for me ;))
Create a small table elsewhere in in the workbook. Let's give it the named range "MyLookup" for the sake of example. This table simply maps the input values to the desired output values, like so:
MyLookup:
Input Output
H H
G H
I H
B E
E E
etc...
Now use this very simple formula to get your result:
=IFERROR(VLOOKUP(LEFT(B25,1),MyLookup,2,FALSE),"")
Make sense?
try this:
=IF(OR(LEFT(AB25,1)="H"; LEFT(AB25,1)="G"; LEFT(AB25,1)="I");"H";"") & IF(OR(LEFT(AB25,1)="B"; LEFT(AB25,1)="E");"E";"") & IF(OR(LEFT(AB25,1)="T"; LEFT(AB25,1)="S"; LEFT(AB25,1)="C");"C";"")

Resources