+ Reply to Thread
Results 1 to 4 of 4

Macro for Automatic Row Insertion

  1. #1
    Registered User
    Join Date
    01-08-2013
    Location
    Brampton
    MS-Off Ver
    Excel 2007
    Posts
    2

    Macro for Automatic Row Insertion

    Working on some automation for my company’s shipping data and was looking for a little Macro help. A test file has been attached.

    Basically, what I want to do is for each row starting on Row 3, the Macro would check the number in the corresponding cell under Column G. If the number is 1, the next row would be checked. If the number is more than 1, the Macro would automatically insert a number of rows equal to the number in the cell minus one (taking Row 4 of the sample file, the number of pieces equals 5 so four rows would be inserted beneath Row 4). Then it would go to the next row which has a filled number in it and repeat the process all the way to the end of the sheet.

    The Stop condition for the row insertion portion of the Macro should be when Excel detects that in the corresponding cell of Column G, the value equals 0.

    I hope I explained this properly. If not, let me know and I'll answer what questions I can.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: Macro for Automatic Row Insertion

    You can use this code.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-08-2013
    Location
    Brampton
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Macro for Automatic Row Insertion

    I tried that code on my file but it did not give me the result I wanted. In the attached file, I ran the code but it did not insert rows at every instance where the piece numbers were greater than 1. My main concern is that the amount of shipping data will be varied where one day we may be seeing five shipments that are 2 pieces and then another day, we see nine shipments that are 2 pieces. And then there are other shipments which may be 3 pieces or 4 pieces and it really depends on the data sample I obtain. Isn't there a way for the Macro to simply recognize the value in Column G and then insert a row based on the conditions I described previously?
    Attached Files Attached Files

  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 for Automatic Row Insertion

    Hi Yasanagi

    You don't really say what you're looking for...

    Is it this
    This.jpg

    Or this
    Or This.jpg

    Or even this
    Or Even This.jpg
    Last edited by jaslake; 02-03-2013 at 05:38 PM.
    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.

+ 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