+ Reply to Thread
Results 1 to 6 of 6

Concatenate a range not just individual cells

  1. #1
    Registered User
    Join Date
    10-15-2014
    Location
    Michigan, US
    MS-Off Ver
    2010
    Posts
    5

    Concatenate a range not just individual cells

    Hello,

    I just began coding using VBA and I am way too much into it right now. This is my first post so I hope I'm in the right place.
    I have a table that looks something like this (just much, much larger):

    Table2.PNG

    I need each cell in the last column (Unique Part ID) to combine values of all the cells on the same row except for the cells in the first column (ID).
    In other words, it is like function CONCATENATE (). However, I do not want the code to use actual references (as it would if I were to record a macro of myself entering the function). Also, the number of Part columns can change, so I need this code to be dynamic. The only thing we know for sure is that all Part columns will be between the ID column and Unique Part ID column.

    The end result would look like the image below:

    Table1.PNG

    I hope you guys are able to assist me. Excel 2016 has a function called CONCAT. With this function, you are able to select a range of cells e.g.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    and it would use each cell in the range as an individual entity while joining strings together. However, this code I'm writing is for MS Excel 2013

    P.S. If you are able to assist by writing a function, would you be able to also include instructions on how the module I am working on can call on that function? I know how to call out each Sub (), but for some reason having issues calling out my functions that I create code for.

    Thank you guys very much!!

  2. #2
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: Concatenate a range not just individual cells

    Hello welcome to the forum.

    This code works for me with Table 1 as a mock-up of your image.

    Please Login or Register  to view this content.
    This runs down the Table's 'Unique Part ID' and concatenates the numbers in each row if the cell is not empty.

    Is this what you're looking to do?

    DBY

  3. #3
    Registered User
    Join Date
    10-15-2014
    Location
    Michigan, US
    MS-Off Ver
    2010
    Posts
    5

    Re: Concatenate a range not just individual cells

    Thank you very much DBY! I will test it once I'm in front of my PC later today and will let you know the outcome.

    I don't mean to be a drag, but I am still in learning stages of VBA.
    By any chance, can you comment on each line of the code to explain what it is that they are doing? No rush on this, I am just trying to understand how and why things work...hoping it would eliminate the need to ask if similar problem arrises.

    Thanks again for your help DBY!

  4. #4
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: Concatenate a range not just individual cells

    Hi
    I need to leave my PC for a while now but I'll add some explanation later.

  5. #5
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Concatenate a range not just individual cells

    Another way

    Please Login or Register  to view this content.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  6. #6
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: Concatenate a range not just individual cells

    Hi
    Below is my code with some remarks included:

    Please Login or Register  to view this content.
    Mike in post #5 has given you a more succinct piece of code as another alternative. You could also turn my example into a UDF (User Defined Function) and add this to the 'Unique ID' column as a formula:

    Please Login or Register  to view this content.
    Spoiled for choice but you did ask!
    Last edited by DBY; 09-10-2016 at 07:10 AM. Reason: Added Trim to finalValue

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. create range from individual cells
    By maxwell888 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-06-2016, 07:21 AM
  2. How to refernce individual cells instead of a range in a function?
    By PM1985 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-12-2015, 04:27 PM
  3. [SOLVED] UDF concatenate randomly chosen cells from range (Horizontal Range)
    By cheesefry in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-15-2014, 03:54 AM
  4. [SOLVED] Appling a range of data to a range of individual cells
    By dubliquid in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 05-08-2013, 07:36 AM
  5. Selecting all individual cells from within a range.
    By milkru1234 in forum Excel General
    Replies: 1
    Last Post: 11-13-2012, 03:03 AM
  6. Excel should lock individual cells or range only
    By centrality in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-30-2006, 03:10 PM
  7. Retrieve individual cells from a range changed between a range
    By baldomero in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-05-2005, 02:31 PM

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