+ Reply to Thread
Results 1 to 7 of 7

Macro - copy and insert multiple rows

  1. #1
    Registered User
    Join Date
    07-01-2013
    Location
    Tel Aviv, Israel
    MS-Off Ver
    Excel 2010
    Posts
    15

    Macro - copy and insert multiple rows

    Hi,

    That is my first thread. I hope someone may be able to help me.

    I am trying to create a macro that breaks up data from one row into multiple rows while copying some of the other row's data. See the attached Excel file that has two spreadsheets – original data and desired output.

    In my original data spreadsheet rows have some info while some of these rows have replacing codes (in columns M onward) which are neither #N/A nor zeros (highlighted). I will call them actual replacing codes. The max number replacing codes may be 25.

    I want the macro to look at the number of actual replacing codes and then insert the same number of additional rows beneath the first row. There should be a separate row for each actual replacing code. If there are no actual replacing codes, no new rows should be added. The replacing codes should be added at the first column while info from B to K columns should be copied. The original M columns onward can be deleted or left for manual deletion.

    If it is not too complicated then "Y" should be inserted at the L column of the desired output spreadsheet to indicate that this row was added and the same actual replacing codes that where inserted at the first column should be added in column. If it is too complicated please ignore this part.

    The number of rows in the original data is not a fixed number so the macro should be able to recognize it. All cells are text (i.e not numbers).

    Any suggestions would be greatly appreciated! Let me know if there are any questions and thanks for all those who will try and help.


    Thanks much, Yoram
    Attached Files Attached Files

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro - copy and insert multiple rows

    Hi yedry101

    Welcome to the Forum!!

    This Code in the attached appears to do as you require. CTRL + x will invoke the Code.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    07-01-2013
    Location
    Tel Aviv, Israel
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Macro - copy and insert multiple rows

    Hi John,
    What a welcome. Thanks you so much for your prompt response. It is great.
    There is one issue. Some of the inserted cells were probably defined as general and not as text. At the sample I have provided text cell such as 02.21 and 041.41 (column M) have become 2.21 and 4.41 when inserted in columns A and H. Is there a way to solve it?
    Regards, Yoram
    Last edited by yedry101; 12-09-2013 at 05:19 PM.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro - copy and insert multiple rows

    Hi yedry101

    They appear to be coming across properly in Column A (true?) but not Column H. I'll look at it...

  5. #5
    Registered User
    Join Date
    07-01-2013
    Location
    Tel Aviv, Israel
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Macro - copy and insert multiple rows

    Hi John,
    I've found a simple solution. I define column A and H as text ones before I invoke the macro.
    Thanks so much,
    Yoram

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro - copy and insert multiple rows

    Hi Yoram

    Simple Solutions are always the best Solutions...If you want the Code to do it for you add the three indicated Lines of Code
    Please Login or Register  to view this content.

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro - copy and insert multiple rows

    Hi Yoram

    You're welcome...glad I could help. Thanks for the Rep.

    If this resolves your issue please mark your Thread as SOLVED.

    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:
    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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. Macro to insert rows in multiple sheets and copy formulas
    By syt0x in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-25-2013, 11:06 AM
  2. [SOLVED] Macro - copy and insert multiple rows
    By Shazzapg in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-22-2013, 10:37 AM
  3. Excel Macro to insert two rows based on condition and copy and paste multiple cells
    By mannabhalo in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-13-2012, 12:56 PM
  4. [SOLVED] Insert Multiple Rows Based Off Number in Cell and Copy Data From Above New Rows
    By tstell1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2012, 04:15 PM
  5. Replies: 2
    Last Post: 04-21-2011, 07:13 PM

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