+ Reply to Thread
Results 1 to 9 of 9

How to take data from columns in some rows and insert in new row?

  1. #1
    Registered User
    Join Date
    07-30-2010
    Location
    South Pole
    MS-Off Ver
    Excel 2010
    Posts
    99

    Question How to take data from columns in some rows and insert in new row?

    I've got a big table that looks like this:

    A B C
    1 USA English Spanish
    2 England English
    3 Canada English French

    Now whenever there is any data present in column C I need to copy the row's content into a new row below, and insert the data in column B. So it looks like this:

    A B C
    1 USA English
    2 USA Spanish
    3 England English
    4 Canada English
    5 Canada French

    I have been messing around but can't find a good way to accomplish this. Would anyone please help me?

  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 take data from columns in some rows and insert in new row?

    I have got a VBA code for you.
    Please Login or Register  to view this content.
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button.
    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 Contributor tkowal's Avatar
    Join Date
    11-20-2010
    Location
    Miami, Fl
    MS-Off Ver
    Excel 2010
    Posts
    150

    Re: How to take data from columns in some rows and insert in new row?

    This seems to work:

    Insert this macro into a new module and run the macro CleanData
    Please Login or Register  to view this content.
    Ted
    "Live Long and Prosper"

  4. #4
    Registered User
    Join Date
    07-30-2010
    Location
    South Pole
    MS-Off Ver
    Excel 2010
    Posts
    99

    Re: How to take data from columns in some rows and insert in new row?

    Wow! Many thanks for your reply! Although I used to program in my teens I'm afraid I can't tweak your scripts so that they fit the actual worksheet I'm working with. The example I gave was simplified (as I thought the answer was simple as well).

    The actual table has data in columns A-Q. The columns with data I need to move to a new row (if applicable) are J, K & L. Every time there is something in either of these columns each cell needs a new row with column A copied to the new row. So if there is data in column J then 1 new row is needed, if there is data in J & K then 2 new rows are needed, etc.

    I tried modifying both your scripts but without success. Would give me a hint what variables to change for this?

    Again, a big thank you!

  5. #5
    Forum Contributor tkowal's Avatar
    Join Date
    11-20-2010
    Location
    Miami, Fl
    MS-Off Ver
    Excel 2010
    Posts
    150

    Re: How to take data from columns in some rows and insert in new row?

    What about columns B-I and M-Q do they need to be copied down as well?

    Does the data in J-L need to be cleared?

    A small sample workbook with the raw data and another sheet of what you want it to look like would be of great help in assisting you.

  6. #6
    Forum Contributor tkowal's Avatar
    Join Date
    11-20-2010
    Location
    Miami, Fl
    MS-Off Ver
    Excel 2010
    Posts
    150

    Re: How to take data from columns in some rows and insert in new row?

    Took a guess on what you wanted. The code is not very efficient but works. I attached a work book with the macro ...
    FunkyCopyDown.xlsm

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-30-2010
    Location
    South Pole
    MS-Off Ver
    Excel 2010
    Posts
    99

    Re: How to take data from columns in some rows and insert in new row?

    This seems to solve my troubles, wow. Many thanks for your swift help! I wouldn't mind sending you money for a beer if you have a way to donate to you.

    Cheers, and thank you!

    I will test this on my live data tomorrow and report back.

  8. #8
    Registered User
    Join Date
    07-30-2010
    Location
    South Pole
    MS-Off Ver
    Excel 2010
    Posts
    99

    Re: How to take data from columns in some rows and insert in new row?

    Quote Originally Posted by janschepens View Post
    I will test this on my live data tomorrow and report back.
    This works just as I want it to, thank you again!

  9. #9
    Forum Contributor tkowal's Avatar
    Join Date
    11-20-2010
    Location
    Miami, Fl
    MS-Off Ver
    Excel 2010
    Posts
    150

    Re: How to take data from columns in some rows and insert in new row?

    I am glad.... just bear in mind that I took a brute force approach to your problem. The code is done without any finesse or thought of efficiency.

    Enjoy!

+ 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