+ Reply to Thread
Results 1 to 11 of 11

Concatenating unique cells (vertically), leaving "; " between results (for emails)

  1. #1
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Concatenating unique cells (vertically), leaving "; " between results (for emails)

    Hi all
    I'm creating a macro to compile some emails but taking the necessary addresses information from the spreadsheet.

    I have some email addresses in lets say column H (row 8 downwards). Lets say as per example below.

    ----------------- ------------col H
    Row 8--------------- empty cell-----------
    Row 9--------------- empty cell-----------
    Row 10------- John.smith1@hotmail.com
    Row 11------- John.smith1@hotmail.com
    Row 12------- John.smith1@hotmail.com
    Row 13--------------- empty cell-----------
    Row 14------- John.smith14@hotmail.com
    Row 15------- John.smith18@hotmail.com
    Row 16------- John.smith24@hotmail.com
    Row 17--------------- empty cell-----------
    Row 18------- John.smith30@hotmail.com

    Now, I'm after a macro or formula that would look the information from H8 (inclusive) downwards as far as per last cell used in column A. Now it should take all the unique email addresses and concatenate them together and use "; " (read semicolon + 1 space) and populate this into cell H3.

    In our example the correct result in H3 would be like this:
    John.smith1@hotmail.com; John.smith14@hotmail.com; John.smith18@hotmail.com; John.smith24@hotmail.com; John.smith30@hotmail.com;

    But not like this:
    John.smith1@hotmail.com; John.smith1@hotmail.com; John.smith1@hotmail.com; John.smith14@hotmail.com; John.smith18@hotmail.com; John.smith24@hotmail.com; John.smith30@hotmail.com;


    I have attached and example spreadsheet. It has sheet "Before", "After" and ""But not like this"

    My intention is use some email compiling macros, that would take the email addresses from H3.

    Does anyone know how to achieve this sort of concatenation?
    Any help is greatly appreciated.
    Cheers
    Attached Files Attached Files
    Last edited by rain4u; 09-21-2011 at 08:36 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Concatenating unique cells (vertically), leaving "; " between results (for emails

    Hello rain4u,

    The macro below setups up both the recipients and CC email columns "H3" and "I3" with the unique addresses separated by a semi-colon and a space. It has been added to the attached workbook.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Concatenating unique cells (vertically), leaving "; " between results (for emails

    Brilliant stuff! Exactly what I was after. Much appreciated!
    Cheers

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Concatenating unique cells (vertically), leaving "; " between results (for emails

    Hello Rain4u,

    Glad you like it. That will be 25 cents to the egress.

  5. #5
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Concatenating unique cells (vertically), leaving "; " between results (for emails

    Hehe. I think I rushed with the praises. Essentially it works with small bug. Namely in I3 the the following should not be there as its information from H column:
    Please Login or Register  to view this content.


    Any ideas?

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Concatenating unique cells (vertically), leaving "; " between results (for emails

    Hello rain4u,

    Looks like I owe a refund. WTF is going on? I will look this over to find the cause. This should not be happening.

  7. #7
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Concatenating unique cells (vertically), leaving "; " between results (for emails

    Thanks for helping me out.
    PS! I charge interest with refunds. Muahahahahaha a

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Concatenating unique cells (vertically), leaving "; " between results (for emails

    Hello Rain4u,

    What a beginner's mistake! I did not clear the Recipients string before the next call.

    Here is the corrected code...
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Concatenating unique cells (vertically), leaving "; " between results (for emails

    Cheers.Its working correctly. Awesome code. I will try to learn from it.
    Just out of curiosity how would I have to replace "; " to act as return, i.e. so it would push the next line down (sort of when you are typing within cell and you pres Alt + Enter to still type within the cell but one line below)?


    Thanks for the help buddy. Brilliant stuff

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Concatenating unique cells (vertically), leaving "; " between results (for emails

    Hello Rain4u,

    To have the text wrap in the cell requires adding a vertical tab character ANSI character 10. In VBA you can concatenate a Chr(10) into the string.

  11. #11
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Concatenating unique cells (vertically), leaving "; " between results (for emails

    Thank you for the tip!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1