+ Reply to Thread
Results 1 to 8 of 8

how to transpose data from one column into multiple rows?

  1. #1
    Registered User
    Join Date
    11-11-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    46

    how to transpose data from one column into multiple rows?

    Hi,

    I have tex data in one column. It represents strings of POS tags assigned to each word in coherent sentences, e.g.:

    nv
    j
    pp
    n1
    n2
    v

    n1
    pp
    n2
    v


    The strings are separated by one-cell space and are of variable length as they represent real sentences from n actual text.

    How to transpose these strings from a column into multiple rows so that a sentence string goes into a row at a time?
    My knowledge is limited to the simplest use of the transpose function which does not work for it transposes the entire column into one row only.
    Thanks,
    G

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: how to transpose data from one column into multiple rows?

    You will need to explain some more as its not very clear.

    Why not attach a sample file showing how your data looks like and how you want it to look like?

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,791

    Re: how to transpose data from one column into multiple rows?

    In the attached file I put your example data in column A starting with A2, and this formula in B2:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This was then copied down to row 20 (i.e. beyond your data), and it sets up a simple sequence which will allow up to 99 tags in one sentence.

    Then I put this formula in D2:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    and this was then copied across (to column L, but it could be further if required), and the formulae from D2:L2 were then copied down (to row 5, but could be further), to give you the results you require.

    Hope this helps.

    Pete
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    11-11-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: how to transpose data from one column into multiple rows?

    Hi Pete,

    Thanks! It works.

    If you don't mind, could you talk me through the formulas so that I'm not just reduced to copy/paste.

    Thanks, Gabriele
    Last edited by arlu1201; 11-11-2012 at 10:21 AM. Reason: Removed whole post quote.

  5. #5
    Registered User
    Join Date
    11-11-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: how to transpose data from one column into multiple rows?

    Hi Arlette,

    I suppose no need for attaching my real data as Pete has already provided a solution. I guess there might be other ways to deal with that but, as his way is working, I'm happy with that .

    Thanks for response!
    Gabriele

    Quote Originally Posted by arlu1201 View Post
    You will need to explain some more as its not very clear.

    Why not attach a sample file showing how your data looks like and how you want it to look like?

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: how to transpose data from one column into multiple rows?

    Sure Gabriele. Even i liked Pete's solution, so you do not have to attach a file.

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,791

    Re: how to transpose data from one column into multiple rows?

    In the first formula I gave you, this part:

    ROUND(B1+0.01,2)

    just adds 0.01 to the previous value, so it forms a simple counter as it is copied down the column, but this is part of an IF statement, so it only does that if A2 is not blank. If it is blank, then the formula will return a value which is the next whole number by means of this part:

    INT(MAX(B$1:B1))+1

    (i.e. find the largest number of all the previous cells, take the whole number part of it, and then add 1), but it will only do this if the next cell in column A is not blank - in this case it will return a blank, as that represents the end of the series of tags. So, we end up in column B with a series of numbers, where the decimal values are a count of the number of tags we have in a particular sentence, and the whole number part represents the sentence number, and a whole number with no decimal values indicates a new sentence. That means that we then need another formula which will make use of rows and columns to enable us to extract data in the correct sequence - we effectively want the tags from column A which have this pattern of numbers:

    0.01, 0.02, 0.03, 0.04, 0.05, and so on
    1.01, 1.02, 1.03, 1.04,
    and so on.

    That is what the second formula does - it uses ROWS($1:1)-1 to form the integer part, (and this will increment on successive rows), together with COLUMNS($A:A)/100 to form the decimal part (which will increment on successive columns), and the MATCH function attempts to find where this number exists in column B. If there is an exact match, the INDEX function will return the corresponding value from column A, but if not the IFERROR function ensures that a blank cell is returned instead.

    Hope this helps.

    Pete
    Last edited by Pete_UK; 11-11-2012 at 10:45 AM.

  8. #8
    Registered User
    Join Date
    11-11-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: how to transpose data from one column into multiple rows?

    Cool! Even I understand .
    Many thanks,
    Gabriele

    Quote Originally Posted by Pete_UK View Post
    In the first formula I gave you, this part:

    ROUND(B1+0.01,2)

    just adds 0.01 to the previous value, so it forms a simple counter as it is copied down the column, but this is part of an IF statement, so it only does that if A2 is not blank. If it is blank, then the formula will return a value which is the next whole number by means of this part:

    INT(MAX(B$1:B1))+1

    (i.e. find the largest number of all the previous cells, take the whole number part of it, and then add 1), but it will only do this if the next cell in column A is not blank - in this case it will return a blank, as that represents the end of the series of tags. So, we end up in column B with a series of numbers, where the decimal values are a count of the number of tags we have in a particular sentence, and the whole number part represents the sentence number, and a whole number with no decimal values indicates a new sentence. That means that we then need another formula which will make use of rows and columns to enable us to extract data in the correct sequence - we effectively want the tags from column A which have this pattern of numbers:

    0.01, 0.02, 0.03, 0.04, 0.05, and so on
    1.01, 1.02, 1.03, 1.04,
    and so on.

    That is what the second formula does - it uses ROWS($1:1)-1 to form the integer part, (and this will increment on successive rows), together with COLUMNS($A:A)/100 to form the decimal part (which will increment on successive columns), and the MATCH function attempts to find where this number exists in column B. If there is an exact match, the INDEX function will return the corresponding value from column A, but if not the IFERROR function ensures that a blank cell is returned instead.

    Hope this helps.

    Pete

+ 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