+ Reply to Thread
Results 1 to 5 of 5

Repetitive Concatenation

  1. #1
    Registered User
    Join Date
    05-15-2009
    Location
    New York, USA
    MS-Off Ver
    Excel 2007
    Posts
    74

    Repetitive Concatenation

    All,

    I am getting ready to create a spreadsheet to list vendor's names and emails along with other data. I would like to include at the bottom of the email addresses a quick copy and paste distribution list. I have achieved this in the past by using a similar formula:

    Please Login or Register  to view this content.
    As you can see it will become very time consuming and not very easy to add names if it gets much longer then 10 names. I know there has to be a way to simplify this process. I have attached an example spreadsheet for your reference. Any and all help is greatly appreciated!
    Attached Files Attached Files
    Last edited by gmcconnell; 02-03-2010 at 05:41 PM.
    Thank you for your time and help,

    Glenver McConnell

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Repetitive Concatenation

    You need a User defined function, I think to do what you need.

    If you add this popular code, developed by Harlan Grove, to a new module in the VB editor:

    Please Login or Register  to view this content.
    and then apply like this:

    =aconcat(B3:B5,"; ")
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    05-15-2009
    Location
    New York, USA
    MS-Off Ver
    Excel 2007
    Posts
    74

    Re: Repetitive Concatenation

    Thank you, it works great! The only thing I would like to ask is could you please re-submit with some more comments so I can study the code and understand it better?

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Repetitive Concatenation

    I am not an expert in VBA... so not sure if I explain it exactly right...

    but basically

    Function aconcat(a As Variant, Optional sep As String = "") As String

    creates the function and says that the arguments must consist of a variable, in this case "a" is the variable and is defined as a variant or pretty much could be an integer, string, etc...

    sep is the variable for the separator you want to use, which has to be string (text) and the default is a null... The whole function results as a string...

    The function then determines if A is a range, like A1:C1, if it is it concatenates each of the cell values with whatever separator you chose...

    If a is not a range, it checks if it is an array (i think this means, something like A1, A2, A3.. and if so concatenates each with a separator

    and lastly if it is a single element it just add the separator to that

    Lastly , since concatenation will add a separator to each cell element, it means the last one too will have a separator after.. so the last formula takes the left part of the whole string minus the width of one sepator... so that it effectively removes the last occurrance of a separator at the end of the whole string...

    Hope that is all right...


    ... if someone else can explain it better... please feel free...

  5. #5
    Registered User
    Join Date
    05-15-2009
    Location
    New York, USA
    MS-Off Ver
    Excel 2007
    Posts
    74

    Re: Repetitive Concatenation

    Thanks again!

+ 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