+ Reply to Thread
Results 1 to 6 of 6

VBA to Insert Blank Row based on matching values

  1. #1
    Registered User
    Join Date
    09-07-2008
    Location
    Middletown
    Posts
    33

    VBA to Insert Blank Row based on matching values

    Hello All,

    I'm trying to create a VBA code that does the following:

    I'm trying to get the code to insert a blank row after the last row with a T in column AA it for matching values in column B. Then continue up column B identifying the next set of matching values, find the last corresponding row with a T in column AA and insert a line underneath it.

    Here's an example of what the code would do to a set of data.


    For example:

    Col. B: Column AA:
    Loc001 TV
    Loc002 T
    Loc002 T
    insert line here
    Loc003 XRT
    Loc004 T
    Loc004 T
    Loc004 T
    insert line here
    Loc005 FFT
    Loc006 T
    insert line here
    Loc007 T
    insert line here
    Loc008 T
    Loc008 T
    would not insert a line here because Loc008 does not have only "T"
    Loc008 XRT
    Loc009 T
    insert line here
    Loc010 FRT

    So it always inserts a line after the last T for the same location if and only if there is only T's in that set of locations. Any ideas?

    Thank you!

    Note this is cross posted at http://www.mrexcel.com/forum/excel-q...ml#post4053172

  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: VBA to Insert Blank Row based on matching values

    Maybe:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    09-07-2008
    Location
    Middletown
    Posts
    33

    Re: VBA to Insert Blank Row based on matching values

    Thanks John. Can you explain what the End(3) means and the 2 in Row To?

    The example I showed above can vary in length and number of Loc's can be more than 3.

    Thanks!

    PS (I like the usage of my handle as the name of the sub - nice touch!)

  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: VBA to Insert Blank Row based on matching values

    You're welcome. The End(3) is shorter version of the statement End(xlup) which you are probably more familiar with. .Row refers to the row. Therefore the line refers to the last cell with data in Column B. Not sure about what you mean "number of Loc's can be more than 3"

  5. #5
    Registered User
    Join Date
    09-07-2008
    Location
    Middletown
    Posts
    33

    Re: VBA to Insert Blank Row based on matching values

    Hi John,

    Thanks for the explanation. I'm trying to integrate the code into my worksheet and noticed something:

    It works partially. For example:

    Col. B Col. AA
    Loc001 T
    your code inserts a line here which is correct
    Loc002 T
    Loc002 RSS
    your code does not insert a line here which is correct
    Loc003 T
    Loc003 T
    i need a line inserted here, but the code does not do that

    I'm trying to get a code that always inserts a line after the LAST T for the same location IF AND ONLY IF there are only T's in that set of locations. Any other thoughts or ideas on how to modify the code to do that?

    Thanks!

  6. #6
    Registered User
    Join Date
    09-07-2008
    Location
    Middletown
    Posts
    33

    Re: VBA to Insert Blank Row based on matching values

    John,

    My sincerest apologies! The code does work. There was a little user error on my end incorporating it into my sheet!

    Thank you!

+ 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. I'm hoping to insert a blank row before all non-blank cell values
    By terbecker in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-25-2012, 01:17 PM
  2. After insert new record, insert values in row based on first cell in row
    By frankienap in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-04-2012, 11:36 AM
  3. Replies: 8
    Last Post: 05-20-2011, 11:36 AM
  4. insert blank rows based on columns a values numerically
    By elkhole in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-18-2009, 04:57 AM
  5. Match values and insert rows for non-matching values
    By Portmanteau in forum Excel General
    Replies: 1
    Last Post: 04-28-2009, 02:08 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