+ Reply to Thread
Results 1 to 7 of 7

Inserting multiple rows below an exisitng row and copying and pasting that data

  1. #1
    Registered User
    Join Date
    06-20-2012
    Location
    Melbourne
    MS-Off Ver
    Excel 2010
    Posts
    4

    Inserting multiple rows below an exisitng row and copying and pasting that data

    Hi everyone,
    This is my first question on the forum so please be gentle with me!

    I need to create a macro that is similar to ones that I've seen on this forum - I want it to insert rows below an existing row of data and then copy and paste data from the existing row into each of the new empty rows. However, the number of new rows required is determined by the number present in a certain cell (F1) of the existing row. So if the number in F1 is 5, then I need the macro to insert 4 new rows and copy and paste exactly the same data, resulting in 5 rows containing exaclty the same data. Then I want the macro to move on to the next unique row and repeat the process. But if F1 in the next unique row = 1, then I want the macro to ignore that row and move on. In the worksheet I'm using the number in F1 changes for every row. I need the marco to go through a worksheet with about 1000 different rows.

    I hope that makes sense?

    I've attached an small example of the worksheet I'm using. There are 2 tabs, the first tab called 'data' is the raw data, the second tab called 'sorted' is basically what I want the macro to do.

    Any help/tips would be greatly appreciated.
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    05-04-2012
    Location
    Stamford,Connecticut,USA
    MS-Off Ver
    Excel 2003
    Posts
    105

    Re: Inserting multiple rows below an exisitng row and copying and pasting that data

    Here is what you need:
    Please Login or Register  to view this content.
    Don't forget to click on the Star below the posting to show your appreciation for the help received and mark the posting as solved.

  3. #3
    Registered User
    Join Date
    06-20-2012
    Location
    Melbourne
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Inserting multiple rows below an exisitng row and copying and pasting that data

    Hi there,
    Thanks so much for the macro, it looks great.
    I ran it on some data but got the following error message:

    Run-time erro '9':

    Subscript out of range


    I've attched the worksheet that I was trying to run the macro in. I've got no idea how to fix the error, sorry!
    Any further help would be greatly appreciated.
    Cheers
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    05-04-2012
    Location
    Stamford,Connecticut,USA
    MS-Off Ver
    Excel 2003
    Posts
    105

    Re: Inserting multiple rows below an exisitng row and copying and pasting that data

    You must name your sheets "Data" and "Sorted" not quote marks or change the code to suit your naming convention of the worksheets.

    Don't forget to click on the Star below the posting to show your appreciation for the help received and mark the posting as solved.

  5. #5
    Registered User
    Join Date
    06-20-2012
    Location
    Melbourne
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Inserting multiple rows below an exisitng row and copying and pasting that data

    Hiya,
    Thanks for that. I renamed the sheets and the macro does now work, except that it kind of crashes excel. It goes through the data but when it gets to the final row excel freezes and comes up with the 'Not Responding' warning and the spinning wheel of death. When I shut it down using the Task Manager, excel sometimes restarts and the sorted data is there, and sometimes it's not there. I've tried running it on another machine running windows 7 and excel 2010, and also on a mac running excel 2011 and the macro crashes excel on both those machines too. Not sure why or what to do. It seems like it's really close to working. Sorry to keep hassling you!

  6. #6
    Forum Contributor
    Join Date
    05-04-2012
    Location
    Stamford,Connecticut,USA
    MS-Off Ver
    Excel 2003
    Posts
    105

    Re: Inserting multiple rows below an exisitng row and copying and pasting that data

    This is must likely due to the selection of the last row. While the preferred way for many coders is what I used in this example
    Please Login or Register  to view this content.
    I find it more usefull to identify which columns has the largest number of rows and find the last row variable going upwards. For example if you know column "A" has the largest number of cells. Your code would like this:
    Please Login or Register  to view this content.
    So change the first line of the code and make sure you use the appropriate column in the Range object.
    Last edited by RaulRodriguez; 06-22-2012 at 10:07 AM.

  7. #7
    Registered User
    Join Date
    06-20-2012
    Location
    Melbourne
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Inserting multiple rows below an exisitng row and copying and pasting that data

    It's now working like a dream.
    Thanks so much fpr your help!

+ 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