# MS Excel IF / OR / CONCATENATE

Looking for some MS Excel Function assistance.  Would like to "clean-up" insurance policy id's in a spreadsheet.  Unfortunately, the ID's come in varying lengths (containing letters and numbers)

Please review the criteria below.  Either method should accomplish my goal.  Any advice would be greatly appreciated.  Thank you

If the first character in Cell A1 = 0, return A1
If the first charater in Cell A1 = 1, return A1
If the first character in Cell A1 = 2, return A1
If the first character in Cell A1 = C, return A1 minus the last character
If the first character in Cell A1 = H, return A1 minus the last character
If the first character in Cell A1 = L, return A1 minus the last charater

or

IF the last character in Cell A1 = any number, return A1
IF the last character is Cell A1 = a letter, return A1 minus the letter
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Excel & VBA ExpertCommented:
Maybe this....

In the following formula if any of your six criteria is met, the policy id will be returned as per the criteria. See if you get the desired output.
``````=IF(OR(ISNUMBER(SEARCH(LEFT(A1,1),{"0","1","2"}))),A1,IF(OR(ISNUMBER(SEARCH(LEFT(A1,1),{"C","H","L"}))),LEFT(A1,LEN(A1)-1),""))
``````
1
Commented:
I did the 1st method and got this,

``````=IF(OR(LEFT(A1, 1) = "0", LEFT(A1,1) = "1", LEFT(A1, 1) = "2"), A1, IF(OR(LEFT(A1, 1) = "C", LEFT(A1, 1) = "H", LEFT(A1, 1) = "L"), A1 - VALUE(RIGHT(A1)), ""))
``````
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
Oops, I had a typo in that formula. With a slight change it should be,

``````=IF(OR(LEFT(A1, 1) = "0", LEFT(A1,1) = "1", LEFT(A1, 1) = "2"), A1, IF(OR(LEFT(A1, 1) = "C", LEFT(KA1, 1) = "H", LEFT(A1, 1) = "L"), LEFT(A1, 1) & (MID(A1, 2, LEN(A1) -2)), ""))
``````
0
Author Commented:
Thank you both for such quick replies.

SKTNEER i tried your suggestion first because it came in first - worked flawlessly.

After reviewing the results i noticed that some of the Policy ID's starting with C, H or L occasionally (rarely) do not end with a letter - in that case i do not want to delete anything.  Is this possible?

Here is a sample dataset

PolicyID's

ColumnA ColumnB
24CC11112222 should return 24CC11112222
14CC11112222 should return 14CC11112222
HLP111112A should return HLP111112
HLP111112 should return HLP111112
LP1111111 should return LP1111111
LP1111111A should return LP1111111

Takundra - i am getting a Value error on you suggestion. Haven't had a chance yet to play around with it.
0
Author Commented:
sktneer - my coworker was able to get me through the last part of the formula.  thank you again for  your assistance.

Here is what he came up with:

=IF( OR( LEFT(A2,1)="0", LEFT(A2,1)="1", LEFT(A2,1)="2",(ISNUMBER(VALUE(RIGHT(A2,1))))), A2, IF( OR( LEFT(A2,1)="C", LEFT(A2,1)="H", LEFT(A2,1)="L",NOT(ISNUMBER(VALUE(RIGHT(A2,1)))) ), LEFT(A2, LEN(A2)-1), "criteria not met"))
0
Excel & VBA ExpertCommented:
Sorry for the delayed reply as I was busy in some other project.
0
Excel & VBA ExpertCommented:
I think the desired output you have shown doesn't meet the criteria you set initially.

See this....

Original              Desired output      My formula output
HLP111112         HLP111112             HLP11111
LP1111111         LP1111111              LP111111

If the first character in Cell A1 = C, return A1 minus the last character
If the first character in Cell A1 = H, return A1 minus the last character
If the first character in Cell A1 = L, return A1 minus the last charater
0
Commented:
Yeah I posted a follow up comment with a corrected formula that shouldn't be returning value errors. Hope that worked fine.
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.