+ Reply to Thread
Results 1 to 15 of 15

insert rows based on number in cell and copy the data down into the new rows

  1. #1
    Registered User
    Join Date
    04-30-2013
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    14

    insert rows based on number in cell and copy the data down into the new rows

    I was able to insert blank rows with a very helpful macro from this site but I would like to copy same info from the original row into the blank rows - If the number is 4, I want to end up with 4 total rows

    I used this and got 4 blank rows - when what I really want is 3 additional and I would like them to have the same info.


    Please Login or Register  to view this content.
    Last edited by Leith Ross; 05-03-2013 at 07:29 PM. Reason: Added Code Tags

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: insert rows based on number in cell and copy the data down into the new rows

    pziefle,

    Welcome to the Excel Forum.

    To get the most precise answer, it is best to upload/attach a sample workbook (sensitive data scrubbed/removed/changed) that contains an example of your raw data on one worksheet, and on another worksheet your desired results.

    The structure and data types of the sample workbook must exactly duplicate the real workbook. Include a clear and explicit explanation of your requirements.

    To attach your workbook, scroll down and click on the Go Advanced button, then scroll down and click on the Manage Attachments button.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Registered User
    Join Date
    04-30-2013
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: insert rows based on number in cell and copy the data down into the new rows

    here is the database I am working on
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    04-30-2013
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: insert rows based on number in cell and copy the data down into the new rows

    Thank you - I added the file

  5. #5
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: insert rows based on number in cell and copy the data down into the new rows

    efle,

    Thanks for the workbook.

    You did explain what you want to do, but, the below macro may have to be changed in case you wanted to split the value, say 4, where the 4 total rows will each display the number 1.

    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
    2. Open your workbook
    3. Press the keys ALT + F11 to open the Visual Basic Editor
    4. Press the keys ALT + I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
    7. Press the keys ALT + Q to exit the Editor, and return to Excel
    8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

    Please Login or Register  to view this content.
    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

    Then run the InsertRows macro.

  6. #6
    Registered User
    Join Date
    04-30-2013
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: insert rows based on number in cell and copy the data down into the new rows

    That worked for the most part but it did not copy the zip code column into the added rows. One other thing I would like to be able to do is make column J reflect how many of 4. so for the first 4 rows they would be consectively numbered by each group. So the first four rows would have 1 then 2 then 3 and then 4 in cell J. Does that make sense

  7. #7
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: insert rows based on number in cell and copy the data down into the new rows

    pziefle,

    That worked for the most part but it did not copy the zip code column into the added rows.
    In the workbook that you attached, the Zip Code's were in column I.

    And, the macro worked correctly with your attached workbook.

    Please attach the workbook where the macro did not work correctly.
    Last edited by stanleydgromjr; 05-01-2013 at 07:28 PM.

  8. #8
    Registered User
    Join Date
    04-30-2013
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: insert rows based on number in cell and copy the data down into the new rows

    That makes sense, I did add a column in there. I would also like to populate a column that consectively numbers each group. What this spreadsheets need to do is make a facing slip that goes on bundles of mail. So my bundle can only have 200 pieces and say for example the first record has 748 total pieces and I would need 4 bundles for that group - that is where the 4 comes in. But then on this facing slip that i create from this spread sheet I also have to indicate how many bundles for this group so I would like a column that give me 1 for the first row in that group and 2 for the second row and 3 for the third row and then 4 for the 4th row. Then the consecutive numbering would need to start over for the next group. I will attach a spreadsheet
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: insert rows based on number in cell and copy the data down into the new rows

    pziefle,

    It is always better to work with the actual raw data setup.

    With your raw data in columns A thru J, and title route number is in cell A1.

    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    Please Login or Register  to view this content.
    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

    Then run the InsertRowsV2 macro.

  10. #10
    Registered User
    Join Date
    04-30-2013
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: insert rows based on number in cell and copy the data down into the new rows

    You are a genius - many many thanks. I appreciate it very much.

    Take care

  11. #11
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: insert rows based on number in cell and copy the data down into the new rows

    pziefle,

    Thanks for the feedback.

    You are very welcome. Glad I could help.

    And, come back anytime.

  12. #12
    Registered User
    Join Date
    05-04-2013
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: insert rows based on number in cell and copy the data down into the new rows

    Good evening everyone.

    I have a similar requirement and was hoping someone can help me with the code. Attached please find the excel workbook with 2 sheets. The
    first being the data sheet and the second showing what I need a VB program to do. Essentially column 13 has the quantity for the total duplicate rows (row 2 needs to have a total of 4 duplicate rows, row 3 needs to have a total of 2 duplicate rows, etc). Any help would be appreciated.
    Attached Files Attached Files

  13. #13
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: insert rows based on number in cell and copy the data down into the new rows

    eyeman96,

    In the future:

    Please do not post your questions in threads started by others - - this is known as thread hijacking.

    Always start a new thread for your questions and, if you think it helps, provide a link to any other thread as a reference.

    Start a new thread for your question and be sure to give it a search friendly title that accurately describes your need.

    After you create your own New Post, then send me a Private Message with a link to your New Post, and, I will have a look.


    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
    2. Open your workbook
    3. Press the keys ALT + F11 to open the Visual Basic Editor
    4. Press the keys ALT + I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
    7. Press the keys ALT + Q to exit the Editor, and return to Excel
    8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

    Please Login or Register  to view this content.
    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

    Then run the InsertRows_eyeman96 macro.

  14. #14
    Registered User
    Join Date
    05-04-2013
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: insert rows based on number in cell and copy the data down into the new rows

    Thank you so much!

  15. #15
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: insert rows based on number in cell and copy the data down into the new rows

    eyeman96,

    You are very welcome. Glad I could 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