+ Reply to Thread
Results 1 to 11 of 11

Select range of cells on sheet 2 and concatenate into one cell on sheet one

  1. #1
    Registered User
    Join Date
    07-13-2014
    Location
    Seattle, WA
    MS-Off Ver
    2013
    Posts
    4

    Select range of cells on sheet 2 and concatenate into one cell on sheet one

    Hello:

    I am looking for VBA code that will take a range of cells B2:E2, from sheet 2, concatenate them with a space between each cells text string, and paste the result into cell A2 on sheet 1.

    I hope I have explained this well enough, but please feel free to ask for clarification.

    I greatly appreciate the assistance.

    David

  2. #2
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Select range of cells on sheet 2 and concatenate into one cell on sheet one

    Hi,

    Try the solution in the attachment...

    I hope this helps
    Attached Files Attached Files

  3. #3
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Select range of cells on sheet 2 and concatenate into one cell on sheet one

    If I understood it correctly... the following code will do....

    If you wanna fix the range...
    Please Login or Register  to view this content.
    if you wanna specify the range yourself then use following code...
    Please Login or Register  to view this content.
    It takes one argument ie x as range...

    Press Alt + F11 then insert module.... copy the function...
    and enjoy..


    Don't forget to click *

  4. #4
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Select range of cells on sheet 2 and concatenate into one cell on sheet one

    @Vikas: please use code tags when posting code. Also, please use indenting in your code to make it easier to read

  5. #5
    Registered User
    Join Date
    07-13-2014
    Location
    Seattle, WA
    MS-Off Ver
    2013
    Posts
    4

    Re: Select range of cells on sheet 2 and concatenate into one cell on sheet one

    Thanks, I am getting an error message saying invalid use of Me. Any idea why?

  6. #6
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Select range of cells on sheet 2 and concatenate into one cell on sheet one

    The use of Me is in the worksheet context. If you are using my code in a custom module (rather than a worksheet module), then change "Me" to Worksheets("WorksheetName"), or just simply ActiveSheet

  7. #7
    Registered User
    Join Date
    07-13-2014
    Location
    Seattle, WA
    MS-Off Ver
    2013
    Posts
    4

    Re: Select range of cells on sheet 2 and concatenate into one cell on sheet one

    Hello:

    Thank you but I am receiving an error message "expected function or variable" and it highlights the second concaty in line as follows:

    Concaty = Concaty & Space(s) & cell.Value

    Thank you, David

  8. #8
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Select range of cells on sheet 2 and concatenate into one cell on sheet one

    Add Dim concaty As String on the line following Sub Concaty()

  9. #9
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Select range of cells on sheet 2 and concatenate into one cell on sheet one

    I am sorry dwach.. use the following code..
    it will definitely work...


    Please Login or Register  to view this content.
    if it gives any error then check the sheet names..

    Don't forget to click *

  10. #10
    Registered User
    Join Date
    07-13-2014
    Location
    Seattle, WA
    MS-Off Ver
    2013
    Posts
    4

    Re: Select range of cells on sheet 2 and concatenate into one cell on sheet one

    That did it Vikas. Thank you very much, I should have asked 12 hours ago.

  11. #11
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Select range of cells on sheet 2 and concatenate into one cell on sheet one

    Don't forget to mark this thread as solved, and you can help those who have helped you by clicking on the * next to their posts to say thanks and add to their reputation

+ 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. [SOLVED] Transfer cells range to another sheet if first cell of destination range is empty
    By kopapa in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 11-04-2013, 04:32 PM
  2. [SOLVED] Excel Macro to lookup sheet name with a range of cells and paste in the reference sheet
    By mishaq in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-08-2013, 02:55 PM
  3. Replies: 0
    Last Post: 09-12-2012, 02:12 AM
  4. Copy select cells from one sheet into the next available column in another sheet
    By gsjan1 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-31-2012, 05:55 PM
  5. Copy select cells from one sheet into the next available column in another sheet
    By gsjan1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-27-2012, 05:45 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