Reputation:
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:
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)
Upvotes: 1
Views: 9506
Reputation: 6720
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";"")
Upvotes: 1
Reputation: 2302
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?
Upvotes: 1
Reputation: 21
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 ;))
Upvotes: 2