+ Reply to Thread
Results 1 to 23 of 23

VBA to Concatenate

  1. #1
    Forum Contributor Pierce Quality's Avatar
    Join Date
    07-29-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    221

    VBA to Concatenate

    Hello All,

    I'm looking to use VBA to concatenate variable data in columns F:J into column F and could use some help to point me in the right direction. The data in this range will be variable, meaning the number of rows will be unknown, and there will also be unused cells, as illustrated in the attached example workbook.
    This will be part of a larger macro in a master file that copies the concatenated data from column F and pastes it into a sheet in the master file where the macro is stored.
    Here is the code I am using so far:

    Please Login or Register  to view this content.
    Any help would be greatly appreciated, thanks!
    Attached Files Attached Files

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA to Concatenate

    No quite clear on what you want - do you just want the code to concatenate values in columns F:J for all rows with data? Do you need any form of delimiter between the concatenated values?

    Do you then want columns G:J to be cleared, or to stay the same?
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to Concatenate

    Maybe:

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor Pierce Quality's Avatar
    Join Date
    07-29-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: VBA to Concatenate

    Quote Originally Posted by OllyXLS View Post
    No quite clear on what you want - do you just want the code to concatenate values in columns F:J for all rows with data? Do you need any form of delimiter between the concatenated values?

    Do you then want columns G:J to be cleared, or to stay the same?
    Hello OllyXLS, thanks for the reply!

    Yes, I'm just looking for the code to concatenate those values.
    I forgot to include that the delimiter between values should be a space.
    Columns G:J can stay as they are, I will only be pulling the data from column F.

    Thanks!

  5. #5
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA to Concatenate

    Try:
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor Pierce Quality's Avatar
    Join Date
    07-29-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: VBA to Concatenate

    Quote Originally Posted by JOHN H. DAVIS View Post
    Maybe:

    Please Login or Register  to view this content.
    Hello John, thanks for the reply!
    Testing your code now, how do I get spaces in between the vaules? Thanks!

    Quote Originally Posted by OllyXLS View Post
    Try:
    Please Login or Register  to view this content.
    Thanks OllyXLS, L'll be testing this shortly!

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to Concatenate

    This will add spaces

    Please Login or Register  to view this content.

  8. #8
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA to Concatenate

    Careful, though - that will also add spaces even when no value exists in the respective G:J cell... So you may end up with a concatenated cell in F, which has several spaces at the end. Depending on what you're doing next with your data, this may or may not present a problem!

  9. #9
    Forum Contributor Pierce Quality's Avatar
    Join Date
    07-29-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: VBA to Concatenate

    Quote Originally Posted by JOHN H. DAVIS View Post
    This will add spaces
    Thanks John, this worked great!
    What does this do:
    Please Login or Register  to view this content.
    Never saw that before!

    Quote Originally Posted by OllyXLS View Post
    Careful, though - that will also add spaces even when no value exists in the respective G:J cell... So you may end up with a concatenated cell in F, which has several spaces at the end. Depending on what you're doing next with your data, this may or may not present a problem!
    Thanks Olly, in this instance this does not present a problem.

    Here is the final version that I went with:

    Please Login or Register  to view this content.
    Thanks for all the help, much appreciated! Marking this as solved.

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to Concatenate

    Quote Originally Posted by Pierce Quality View Post
    Thanks John, this worked great!
    What does this do:
    Please Login or Register  to view this content.
    Never saw that before!
    The 2 is a row count to stop at - in this case Row 2.
    Step -1 - means from the last row in the column it moves up -1 row.

  11. #11
    Forum Contributor Pierce Quality's Avatar
    Join Date
    07-29-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: VBA to Concatenate

    Quote Originally Posted by JOHN H. DAVIS View Post
    The 2 is a row count to stop at - in this case Row 2.
    Step -1 - means from the last row in the column it moves up -1 row.
    Makes sense, thanks John!

  12. #12
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to Concatenate

    Welcome. Glad to help out.

  13. #13
    Forum Contributor Pierce Quality's Avatar
    Join Date
    07-29-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: VBA to Concatenate

    Quote Originally Posted by JOHN H. DAVIS View Post
    Welcome. Glad to help out.
    John,
    ive been having an issue with an unanticipated variable, sometimes the cells in Column F will be empty, but there will still be data in Columns G:J to merge into column F. Currently, if there is no data in column F nothing is merged.
    Any help would be greatly appreciated, thanks!

  14. #14
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to Concatenate

    Can you attach a file where that is occuring. I ran a test on some dummy data and it appeared to work.

  15. #15
    Forum Contributor Pierce Quality's Avatar
    Join Date
    07-29-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: VBA to Concatenate

    Quote Originally Posted by JOHN H. DAVIS View Post
    Can you attach a file where that is occuring. I ran a test on some dummy data and it appeared to work.
    Thanks John, will do!

  16. #16
    Forum Contributor Pierce Quality's Avatar
    Join Date
    07-29-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: VBA to Concatenate

    John,

    In the attached examples the data labeled "Data2" is not appearing in the master file.

    Thanks!
    Attached Files Attached Files

  17. #17
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to Concatenate

    Quote Originally Posted by Pierce Quality View Post
    John,

    In the attached examples the data labeled "Data2" is not appearing in the master file.

    Thanks!
    I don't see a Data2? Which Columns are you trying to concatenate based on your examples? Is the error occuring in Book1, Book2 or both? Please explain.

  18. #18
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to Concatenate

    Try:

    Please Login or Register  to view this content.
    I think I understand.

  19. #19
    Forum Contributor Pierce Quality's Avatar
    Join Date
    07-29-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: VBA to Concatenate

    Sorry John, I missed the letter in my previous post, its the data Labeled "DataG2" in Book2 thats not appearing to concatanate in the corresponding in column F when when the corresponding cell column F is empty.

    Thanks

  20. #20
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to Concatenate

    Quote Originally Posted by Pierce Quality View Post
    Sorry John, I missed the letter in my previous post, its the data Labeled "DataG2" in Book2 thats not appearing to concatanate in the corresponding in column F when when the corresponding cell column F is empty.

    Thanks
    Did Post 18 fix the problem?

  21. #21
    Forum Contributor Pierce Quality's Avatar
    Join Date
    07-29-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: VBA to Concatenate

    Quote Originally Posted by JOHN H. DAVIS View Post
    Did Post 18 fix the problem?
    Just ran your updated version and it solved the problem!
    Thanks for the help again John, much appreciated!

  22. #22
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to Concatenate

    You're welcome. The Code was looking for the last used cell in Column F. I changed it to the last used row on the Sheet. I assume Column F to be equal to the others.

  23. #23
    Forum Contributor Pierce Quality's Avatar
    Join Date
    07-29-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    221

    Re: VBA to Concatenate

    Thanks John, you are correct!

+ 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. Replies: 2
    Last Post: 04-12-2010, 12:35 PM
  2. [SOLVED] IF, IF, Concatenate?
    By Ken Hudson in forum Excel Formulas & Functions
    Replies: 18
    Last Post: 09-06-2005, 02:05 PM
  3. [SOLVED] Un - Concatenate?
    By Kassie in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2005, 12:05 PM
  4. [SOLVED] IF, IF, Concatenate?
    By savvysam in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  5. [SOLVED] [SOLVED] I know how to concatenate ,can one de-concatenate to split date?
    By QUICK BOOKS PROBLEM- in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 07-26-2005, 01:05 PM

Tags for this Thread

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