+ Reply to Thread
Results 1 to 19 of 19

rowss data into a cell as comma delimited

  1. #1
    Registered User
    Join Date
    08-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    26

    rowss data into a cell as comma delimited

    Hi all,

    My first question in this forum. Wish for a great response.

    I have a table of data. say like

    A B C D E F G H I J

    1 2 1 4 5 1 2
    1 2 3 4 4 3 3
    2 1 3 5 7 4 5
    4 5 7 8 9 6 2

    I want each row to be converted into a comma delimited cell value. For eg. it should turn the first row as 1,2,1,4,5,1,2 AND PUT THIS VALUE in the I column ( leaving out the K column or any cell that i want to ).

    so the next row should be converted to 1,2,3,4,4,3,3 and placed next to the cell where the previous row data was placed.

    so after the operation the table should be like this

    A B C D E F G H ===== I =============J

    1 2 1 4 5 1 2 ======= 1,2,1,4,5,1,2 ====1,2,3,4,4,3,3
    1 2 3 4 4 3 3
    2 1 3 5 7 4 5
    4 5 7 8 9 6 2

    and so on for all 5 rows.

    Also is there any method by which i can just convert the table into a single value moving from row to column and comma delimited. i.e. 1,2,1,4,5,1,21,2,3,4,4,3,3, and so on.

    Thanks all for any help on this !
    Last edited by Ajoo; 09-04-2013 at 11:07 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,620

    Re: rowss data into a cell as comma delimited

    To attach a Workbook
    (please do not post pictures of worksheets)
    • Click Advanced (next to quick post),
    • Scroll down until you see "Manage Attachments",
    • Click that then select "add files" (top right corner).
    • Click "Select Files" find your file, click "open" click "upload"
    • Once the upload is completed the file name will appear below the input boxes in this window.
    • Click "Done" at bottom right to close the Attachment Manager.
    • Click "Submit Reply"

    If you don't post a workbook, that means anyone wishing to help you has to copy and paste from your post to their own.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    08-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: rowss data into a cell as comma delimited

    Thanks for the advice which i will have followed to attach a worksheet.

    The data is in columns A to G. The output I want is as depicted by Column I and also column J. So these two outputs I desire.

    This is a small example but actual file can have many rows and so I wish to use some macro or maybe some VB programming to accomplish this. For the moment I am considering that the length of each row is same but it can also be variable.

    Pls can someone suggest a method.

    Thanks again.
    Attached Files Attached Files
    Last edited by Ajoo; 09-05-2013 at 02:06 AM.

  4. #4
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: rowss data into a cell as comma delimited

    Hi,

    Enter this array formula (please ensure you know how to enter these type of formulas in Excel) in I1 and copy down as required:

    =SUBSTITUTE(SUM(TRANSPOSE(MMULT({1;0},$A1:$G1))*(MMULT(100^(COLUMNS($A1:$G1)-ROW(INDIRECT("1:"&COLUMNS($A1:$G1)))),{1,0}))),0,",")

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: rowss data into a cell as comma delimited

    Macro as an option.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    08-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: rowss data into a cell as comma delimited

    Hi XOR,

    Thanks for this idea. It works for single numbers though. I have zero idea how this is working on single numbers. However it does not give the desired result for double digits or negative numbers like -7. I have also come across another code snippet for achieving the same which i am going to share with all.

    [K1] = Join(Application.Transpose(Application.Transpose(Range("A1:I1"))), ",")

    So this works great for the range. A1:I1. However this works as a Macro and I am unable to make this a formula and insert it directly into the K1 cell like I could do for the code snippet graciously offered by XOR.

    So can anyone help me and tell me how I may use =Join(Application.Transpose(Application.Transpose(Range("A1:I1"))), ",") as a formula / array formula and insert it directly into a cell. I tried it and get #NAME? error.

    Can someone tell me how I can use [K1] = Join(Application.Transpose(Application.Transpose(Range("A1:I1"))), ",") in a macro and use a loop to increment the range A1:I1 to A2:I2 to A3:I3 and so on for the subsequent rows. I am unable to find a way / manner / format for incrementing the row numbers 1, 2 ,3 etc in the ranges. Ai:Ii does not work where i is a variable loop increment. I need something like this.

    Thanks all for all the help so far.

  7. #7
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: rowss data into a cell as comma delimited

    "However it does not give the desired result for double digits or negative numbers like -7."

    Forgive me, but this is precisely why it is important to give as much information as possible in the original post.

    All 28 of the entries in the data sample you provided were single digit numbers, and none of them were negative - if these types are to be considered, would it not have made sense to include one or two in your dataset? Or at least to clarify for what range of values you wish the solution to cover?

    Regards

  8. #8
    Registered User
    Join Date
    08-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: rowss data into a cell as comma delimited

    My apologies XOR. I'll bear that in mind from now on. I do not wish to undermine your help in anyway. Thanks so much for taking the time out.

    Regards.

  9. #9
    Registered User
    Join Date
    08-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: rowss data into a cell as comma delimited

    This code snippet I found works but for one row.

    [K1] = Join(Application.Transpose(Application.Transpose(Range("A1:I1"))), ",")

    So this works great for the range. A1:I1. However this works as a Macro and I am unable to make this a formula and insert it directly into the K1 cell like I could do for the code snippet graciously offered by XOR.

    So can anyone help me and tell me how I may use =Join(Application.Transpose(Application.Transpose(Range("A1:I1"))), ",") as a formula / array formula and insert it directly into a cell. I tried it and get #NAME? error.

    Can someone tell me how I can use [K1] = Join(Application.Transpose(Application.Transpose(Range("A1:I1"))), ",") in a macro and use a loop to increment the range A1:I1 to A2:I2 to A3:I3 and so on for the subsequent rows. I am unable to find a way / manner / format for incrementing the row numbers 1, 2 ,3 etc in the ranges. Ai:Ii does not work where i is a variable loop increment. I need something like this.

    Thanks all for all the help so far.

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: rowss data into a cell as comma delimited

    This code snippet I found works but for one row.
    My code works the same as your snippet, but in all rows, not just one row.

  11. #11
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,620

    Re: rowss data into a cell as comma delimited

    You need to create a User Defined Function (UDF), thus:

    Please Login or Register  to view this content.
    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    Usage:
    Cell K1: =Cells2String(A1:G1)

  12. #12
    Registered User
    Join Date
    08-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: rowss data into a cell as comma delimited

    Thanks guys for such a fantastic response. I have learnt so much. I had no clue that there was something like UDF. This has been a great learning experience. I need to digest all this and check how these work.
    Yes AB33 your code works like a charm. In fact I also used it and checked for -ve numbers and double digit numbers and it is flawless. Thanks loads. I have yet to try out the UDF just suggested ProtonLeah.

    Just one question still remains in my mind and i would like to ask again for clarification. Is there any way to manipulate the row-column value of Ranges like A1:J1. Can i not vary the column values to 2 or 3 and so on using a loop. Either in this form or any of the many other range forms in excel. I hope I am able to make my question clear. I ask this becos I think if these can be manipulated then i think it would be very handy. So any suggestions by anyone?

    Thanks loads all ! Much obliged.

  13. #13
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: rowss data into a cell as comma delimited

    Ajoo,
    The code works on any column length as long as you do not have a complete blank row or column because I used Currentregion, but can easily change if you have blanks.

  14. #14
    Registered User
    Join Date
    08-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: rowss data into a cell as comma delimited

    Hi AB33, yes I have already discovered what you have mentioned. yes it works for any number of columns provided there is no blanks. And yes I wanted to ask what can be done if i have blocks of data separated by blanks. i want the result for each block be placed next to the top row of that block. I am very new to excel VB programming. In fact i would be very happy if you can explain how your code works. That would be so very nice and i am most grateful.

    Thanks loads,
    Ajoo.

  15. #15
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: rowss data into a cell as comma delimited

    Us this line

    Please Login or Register  to view this content.
    Adjust the column H to suite your needs

  16. #16
    Registered User
    Join Date
    08-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: rowss data into a cell as comma delimited

    I will just try it out. Thanks. Please take some time to explain the code so that I may be able to explore it further.

    Thanks !

  17. #17
    Registered User
    Join Date
    08-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: rowss data into a cell as comma delimited

    Hi AB33 ! This works fine except that the composite output of the 2nd block is also appended to the composite of the first block. This should not happen. The combined output of each block should lie against the top row of that block. e.g as below
    Block 1
    ABCD H J
    1234---1,2,3,4------1,2,3,4,2,3,4,5,1,2,1,2
    2345---2,3,4,5
    1212---1,2,1,2

    Block 2
    1278----1,2,7,8--------1,2,7,8,6,5,3,2,1,3,3,1
    6532----6,5,3,2
    1331----1,3,3,1

    So like above the output of column "H" should be seperate for each block.

    I hope this would be clear. Request you once again to explain the code a bit to get me started.

    Thanks loads !

  18. #18
    Registered User
    Join Date
    08-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: rowss data into a cell as comma delimited

    Hi AB33 & the rest of the gurus ! Pls help me conclude this one. Appending my last mail here once again for convenience. Would be very happy if AB33 or any guru here can explain the working of the code given by AB33. After all that's one of the main reasons most of us are here for, to learn. Thanks all !

    Hi AB33 ! This works fine except that the composite output of the 2nd block is also appended to the composite of the first block. This should not happen. The combined output of each block should lie against the top row of that block. e.g as below
    Block 1
    ABCD H J
    1234---1,2,3,4------1,2,3,4,2,3,4,5,1,2,1,2
    2345---2,3,4,5
    1212---1,2,1,2

    Block 2
    1278----1,2,7,8--------1,2,7,8,6,5,3,2,1,3,3,1
    6532----6,5,3,2
    1331----1,3,3,1

    So like above the output of column "H" should be seperate for each block.

    I hope this would be clear. Request you once again to explain the code a bit to get me started.

    Thanks loads !

  19. #19
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,555

    Re: rowss data into a cell as comma delimited

    UDF

    Use in cell like

    =Joincells(A4:I4,",")

    To a Standard module.
    Please Login or Register  to view this content.

+ 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] Data in Column A to Comma Delimited List
    By webdivx in forum Excel General
    Replies: 5
    Last Post: 07-11-2013, 02:16 PM
  2. [SOLVED] comma and dash delimited data to rows
    By sa02000 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-02-2013, 11:01 AM
  3. SUM of values in a comma delimited cell
    By Danexcel in forum Excel General
    Replies: 18
    Last Post: 01-15-2010, 10:59 AM
  4. Splitting Comma Delimited Data
    By yawnzzzz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-22-2008, 01:11 PM
  5. Replies: 1
    Last Post: 01-15-2006, 08:30 AM

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