Results 1 to 8 of 8

Excel 2007 : A macro to insert an empty row based on specified criteria

Threaded View

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

    A macro to insert an empty row based on specified criteria

    Hi folks,

    I am a noob when in comes to macros but I would be grateful for a solution that piggie backs on the macro written below by Leith Ross. I'm looking to write a macro to insert one entire row into a set of data after each data group ends. The macro below only inserts a cell between each data group.

    E.g. Column A contains the following data starting with A1, then A2 etc. I also have data in columns B, C, D, E etc... The empty row would move all data in the row down, not just the column A. However, the criteria for the data group will still be column A. Does this make sense?

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

    I would like to run a macro which will insert one entire row after each similar data sets ends.

    The result would be the following

    A1 = BB
    A2 = BB
    A3 = BB
    A4 = (EMPTY ROW)
    A5 = CC
    A6 = CC
    A7 = CC
    A8 = (EMPTY ROW)
    A9 = DD
    A10 = DD
    A11 = (EMPTY ROW)
    A12 = EE
    A13 = EE


    'Written: Sept. 18, 2007
    'Author: Leith Ross
    'Summary: Add blank cells where the data changes

    Sub AddBlankLines()
    
        Dim Col As Variant
        Dim BlankRows As Long
        Dim LastRow As Long
        Dim R As Long
        Dim StartRow As Long
    
            Col = "A"
            StartRow = 1
            BlankRows = 2
        
                LastRow = Cells(Rows.Count, Col).End(xlUp).Row
                
                Application.ScreenUpdating = False
                
                With ActiveSheet
                    For R = LastRow To StartRow + 1 Step -1
                        If .Cells(R, Col) <> Cells(R - 1, Col) Then
                            .Cells(R, Col).Resize(RowSize:=BlankRows).Insert Shift:=xlDown
                        End If
                    Next R
                End With
      
                Application.ScreenUpdating = True
                
    End Sub
    Thanks in advance.

    Tom
    Last edited by Cutter; 07-18-2012 at 12:04 PM. Reason: Added code tags

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