+ Reply to Thread
Results 1 to 10 of 10

Macro that inserts rows between cells that do not have the same first 5 characters

  1. #1
    Registered User
    Join Date
    01-10-2014
    Location
    Philadelphia
    MS-Off Ver
    Excel 2003
    Posts
    5

    Macro that inserts rows between cells that do not have the same first 5 characters

    Hello,

    I am trying to create a Macro that will look at a specific column and identify when the cell on top of the other cell no longer have the same input.

    ex.

    D
    13 Orange
    14 Orange
    15 Orange
    16 Apple
    17 Apple
    18 Banana
    19 Banana

    I would want two blank rows inserted in between 15 and 16 as well as 17 and 18.
    Also the list I need to break into parts does not always have the exact wording as other cells, but still belong in one group so I was wondering if it could seperate the list based on the first 5 characters in cell.

    Thanks

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro that inserts rows between cells that do not have the same first 5 characters

    Maybe:

    Please Login or Register  to view this content.
    Last edited by JOHN H. DAVIS; 01-10-2014 at 02:52 PM.

  3. #3
    Registered User
    Join Date
    01-10-2014
    Location
    Philadelphia
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macro that inserts rows between cells that do not have the same first 5 characters

    This was a good start; however, this code only inserted cells instead of entire rows and did not insert a cell only if the entire cell matched the next one, but I do not want it to insert rows that have the first 5 characters the same, only cells that have a different first 5 characters should insert 2 rows between them

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro that inserts rows between cells that do not have the same first 5 characters

    Can you attach a sample with a before and after affect?

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-10-2014
    Location
    Philadelphia
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macro that inserts rows between cells that do not have the same first 5 characters

    John Davis before.jpgJohn Davis after.jpg

    I changed your coding so that it would look at column "G" the column that says Discription. I would like everything that starts with [Deflection] to be grouped together without breaks in between them which is why I would like the coding to just look at the first 5 characters to determine if the two rows should be inserted or not.

    Thanks

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro that inserts rows between cells that do not have the same first 5 characters

    .jpg's are hard to read. I meant attaching a file with some sample data. However, try this.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-10-2014
    Location
    Philadelphia
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macro that inserts rows between cells that do not have the same first 5 characters

    Awesome!!! This works. Thank you very much. Sorry about the jpg's, I am new to the forums and to Macros. I would also like to put a bottom border on the last row in each section now and also use =counta to count the items in each section in column "A" and place the count in column "A" in the cell below the section and bold that row. Any chance you could help with that too?

    Thanks

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro that inserts rows between cells that do not have the same first 5 characters

    Maybe:

    Please Login or Register  to view this content.
    Last edited by JOHN H. DAVIS; 01-13-2014 at 12:17 PM.

  9. #9
    Registered User
    Join Date
    01-10-2014
    Location
    Philadelphia
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macro that inserts rows between cells that do not have the same first 5 characters

    That received an error '1004' saying that no cells were found. It still preformed the inserting of the two rows though.

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro that inserts rows between cells that do not have the same first 5 characters

    Can you attach a sample file with some test data?

+ 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. [SOLVED] Macro that inserts rows stopped working
    By jed38 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-16-2013, 09:57 AM
  2. Macro that Inserts a row in between rows (with formulas etc)
    By How How in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-14-2013, 07:49 AM
  3. Macro: Drop Down Menu Selection Inserts Templated Rows
    By nealshah4 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-27-2011, 06:31 PM
  4. Create a Looping macro which copies and inserts rows
    By BenR in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-18-2007, 02:13 PM

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