+ Reply to Thread
Results 1 to 7 of 7

Excel 07 - Macro to insert rows based on criteria

  1. #1
    Registered User
    Join Date
    06-07-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    4

    Excel 07 - Macro to insert rows based on criteria

    Hi all,

    Im hoping someone can assist me. Im looking to write a macro to insert rows into a set of data after each data group ends.

    E.g. Coloum A contains the following data (1 per cell starting with A1, then A2 etc)

    A1 = BB
    A2 = BB
    A3 = BB
    A4 = CC
    A5 = CC
    A6 = CC
    A7 = DD
    A8 = DD
    A9 = EE

    I would like to run a macro which will insert rows after each similar data sets ends

    The result would be the following

    A1 = BB
    A2 = BB
    A3 = BB
    A4 = (BLANK)
    A5 = (BLANK)
    A6 = CC
    A7 = CC
    A8 = CC
    A9 = (BLANK)
    A10 = (BLANK)
    A11 =DD
    A12 = DD
    A13 = (BLANK)
    A14 = (BLANK)
    A15 = EE
    A16 = EE

    In the above example I have inserted 2 new lines between the data sets however having an easy method to change this would be great.

    Hopefully my explanation was clear enough to show what I am trying to do.

    Thanks in advance for your assistance

    Mike

  2. #2
    Registered User
    Join Date
    06-07-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Excel 07 - Macro to insert rows based on criteria

    Just a quick note that the data within the coloumn will change size, soIi need it to search for the last set of data (In the example it would be BB in A3) and insert the lines. However the next day the last occurance of BB might be in A7 and i would need the lines inserted there.

    Thanks again!

  3. #3
    Registered User
    Join Date
    06-07-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Excel 07 - Macro to insert rows based on criteria

    Bump, can anyone assist with the above query?

    Cheers

    Mike

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Excel 07 - Macro to insert rows based on criteria

    Hello smic,

    This should work for your needs.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    06-07-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Excel 07 - Macro to insert rows based on criteria

    Thankyou so much! It worked perfectly!!

  6. #6
    Registered User
    Join Date
    07-18-2012
    Location
    Markham, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Excel 07 - Macro to insert rows based on criteria

    Hi folks,

    I am a noob when in comes to macros but I, like smic, would be grateful for a solution that piggie backs on the macro written above. I tried this macro but I believe this only adds a cell in the column noted, in this case "B".

    What would be needed in the script above to insert the ENTIRE empty row based on the same criteria as noted by smic.

    Example: Before

    A B C
    1 10 AA X
    2 5 AA X
    3 7 AA X
    4 3 BB X
    5 8 BB X
    6 6 BB X
    7 1 CC X
    8 3 CC X

    After

    A B C
    1 10 AA X
    2 5 AA X
    3 7 AA X
    4 (Empty)
    5 3 BB X
    6 8 BB X
    7 6 BB X
    8 (Empty)
    9 1 CC X
    10 3 CC X

    Thanks in advance.

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Excel 07 - Macro to insert rows based on criteria

    TBJV,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    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]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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