Complicated IF formula (how do I combine 11 if statements)

alinka

Board Regular
Joined
Oct 30, 2002
Messages
70
Hi Excel wizards,

I am a newbie to excel and have a complicated problem. See spreadsheet below for reference, plz.

This is what I need to do:

1) I regularly get a large amount of name data in columns A through C. Each row has an email syntax in Column D. In Column E, I created a formula that writes an email address for the corresponding syntax. I have 11 email syntaxes in total.

2) I need a formula that can read an email syntax in D, and use one of my 11 formulas to create an email address. In other words, I want the formula to do this:

a) IF we find "first.last" in D, use formula =A2&"."&C2&(MID(D2,(FIND("@",D2)),50))

b) IF we find "first_last" in D, use formula =A3&"_"&C3&(MID(D3,(FIND("@",D3)),50))

c) IF we find "first.m.last" in D, use formula =A4&"."&(IF(B4="","",(LEFT(B4,1))&"."))&C4&(MID(D4,(FIND("@",D4)),50))

and so on for the next 8 syntaxes that are shown in D.

So, there are 11 IF statements, that need to be combined into 1 formula. How can I go about doing this??? Or do you envision an easier way? Is it possible to write a vb code that would do this? ANY HELP IS APPRECIATED. THANKS!!!!
email-syntax.xls
ABCDE
1FirstNameMiddleLastNameEmailSyntaxEmailFormula
2AlanJLacyfirst.last@company.comAlan.Lacy@company.com
3WilliamCWhitefirst_last@company.comWilliam_White@company.com
4MichaelBuxtonfirst.m.last@company.comMichael.Buxton@company.com
5JeromeBeKarlinfirst_m_last@company.comJerome_B_Karlin@company.com
6WilliamJackRudolphsenfirst_m_last@company.comWilliam_J_Rudolphsen@company.com
7MarkAWagnerflast@company.comMWagner@company.com
8RobertMKrallastf@company.comKralR@company.com
9WilliamLHubbsfmlast@company.comWLHubbs@company.com
10AlanJLacyfirstlast@company.comAlanLacy@company.com
11JeromeKarlinskyFLast>7@company.comJKarlins@company.com
12WilliamRudolphsenFLast>8@company.comWRudolphs@company.com
Sheet1
 
Ok alinka, try this out:


<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> emailAddy5()

    <SPAN style="color:#00007F">Dim</SPAN> a <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, b <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, c <SPAN style="color:#00007F">As</SPAN> Range
    <SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>
    i = ActiveCell.Row
    <SPAN style="color:#00007F">Set</SPAN> c = Range("G" & i)
    a = Range("E" & i).Value
    b = a & "@company.com"
    <SPAN style="color:#00007F">Select</SPAN> <SPAN style="color:#00007F">Case</SPAN> b
        <SPAN style="color:#00007F">Case</SPAN> "first.last@company.com"
            Range("G" & i).Formula = "=A" & i & "&"".""&C" & i & "&""@""&F" & i
        <SPAN style="color:#00007F">Case</SPAN> "first_last@company.com"
            Range("G" & i).Formula = "=A" & i & "&""_""&C" & i & "&""@""&F" & i
        <SPAN style="color:#00007F">Case</SPAN> "first.m.last@company.com"
            Range("G" & i).Formula = "=A" & i & "&"".""&(IF(B" & i & "="""","""",(LEFT(B" & i & ",1))&"".""))&C" & i & "&""@""&F" & i
        <SPAN style="color:#00007F">Case</SPAN> "first_m_last@company.com"
            Range("G" & i).Formula = "=A" & i & "&""_""&(IF(B" & i & "="""","""",(LEFT(B" & i & ",1))&""_""))&C" & i & "&""@""&F" & i
        <SPAN style="color:#00007F">Case</SPAN> "flast@company.com"
            Range("G" & i).Formula = "=LEFT(A" & i & ",1)&C" & i & "&""@""&F" & i
        <SPAN style="color:#00007F">Case</SPAN> "lastf@company.com"
            Range("G" & i).Formula = "=C" & i & "&LEFT(A" & i & ",1)&""@""&F" & i
        <SPAN style="color:#00007F">Case</SPAN> "fmlast@company.com"
            Range("G" & i).Formula = "=LEFT(A" & i & ",1)&LEFT(B" & i & ",1)&C" & i & "&""@""&F" & i
        <SPAN style="color:#00007F">Case</SPAN> "firstlast@company.com"
            Range("G" & i).Formula = "=A" & i & "&C" & i & "&""@""&F" & i
        <SPAN style="color:#00007F">Case</SPAN> "lastfirst@company.com"
            Range("G" & i).Formula = "=C" & i & "&A" & i & "&""@""&F" & i
        <SPAN style="color:#00007F">Case</SPAN> "FLast>7@company.com"
            Range("G" & i).Formula = "=LEFT(A" & i & ",1)&LEFT(C" & i & ",7)&""@""&F" & i
        <SPAN style="color:#00007F">Case</SPAN> "FLast>8@company.com"
            Range("G" & i).Formula = "=LEFT(A" & i & ",1)&LEFT(C" & i & ",8)&""@""&F" & i
        <SPAN style="color:#00007F">Case</SPAN> <SPAN style="color:#00007F">Else</SPAN>
            Range("G" & i).Formula = "No Set Syntax"
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Select</SPAN>
    c.Value = c.Value
    ActiveSheet.Hyperlinks.Add Anchor:=c, Address:= _
        "mailto:" & c, TextToDisplay:=c.Text

<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>


The only thing with this one is, you need to have the cell selected where you want the address to go, in column G. And works ok for me, hope it helps.

Mike, yes I tried mentioning that earlier, that I pieced part of your code in, with the hyperlinking and hardcoding the Case's. Great work! (as usual!)

Let me know how this works alinka! :)
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Btw, fwiw as a useful tip (if you don't do this already) you could also assign it a shorcut key. If you press Alt + F8, select the macro in question (emailAddyx) -> Options, in the 'Ctrl +' field type in the letter of the keyboard you wish for a shortcut key. I'd suggest Alt + k or Alt + m, something that isn't really used already, like Alt + S is Save type of thing.
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top