Link to home
Start Free TrialLog in
Avatar of AndresHernando
AndresHernando

asked on

Excel VBA - sort email addresses inside of a merged range

I have multiple email addresses inside a named merged range rEmailDistrib.  The email addresses are separated by semicolon, or comma, or colon, or space(s).  I need to manipulate thus:
1) Leave all email addresses inside the merged range
2) Sort A-Z, one email address per line inside the merged range
3) Put semicolon at the end of each email address (get rid of all spaces)

For example, original contents of rEmailDistrib is:
abc4@mail.com,abc2@mail.org   abc1@mail.mil; abc3@mail.swa.mil: abc5@mail.com

New content of rEmailDistrib would be...
abc1@mail.mil;
abc2@mail.org;
abc3@mail.swa.mil;
abc4@mail.com;

Maybe the way to approach is by starting out with a "helper" worksheet cell containing "=Clean(rEmailDistrib)"

Thanks, --Andres
Avatar of Jacques Geday
Jacques Geday
Flag of Canada image

you range rEmailDistrib contains how many rows/cells ? what is its address ? do you have 1 email per cell or some cells have many emails ?
gowlfow
1) I read your post again and you mention 'merged name range' so I assume it is 1 cell (merged) that you maybe enlarged and it contain all the emails that you need sorted/cleaned

Pls confirm my understanding correct.

2) When they are cleaned where do you want the emails to show in hte same named range each one on 1 line ?

gowflow
Avatar of AndresHernando
AndresHernando

ASKER

Hi gowflow,  
Yes, one single cell (merged range really) has all the text that needs to be cleaned and sorted.
I have figured out how to clean the text and now have a long string with no spaces, with each email address separated by a semicolon ";"
Now I need to sort them in the same cell and have a line feed at the end of each so that inside the cell the contents will be
abc1@mail.mil;
abc2@mail.org;
abc3@mail.swa.mil;
abc4@mail.com;
.
.
Thanks, --Andres
ASKER CERTIFIED SOLUTION
Avatar of Jacques Geday
Jacques Geday
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In addition, if your named range is diffrent just change in this
CleanEmails ActiveSheet.Name & "!rEmailDistrib"

the rEmailDistrib by hte new named range where the emails exist.
gowflow
gowflow, nice code!  I didn't know about the SPLIT function.  Works nicely.  THANKS!!  --Andres
Your welcome Andres anytime and tks ofr the grade
gowflow