+ Reply to Thread
Results 1 to 2 of 2

Formula to add a blank row if 2 values differ

Hybrid View

  1. #1
    Registered User
    Join Date
    02-25-2009
    Location
    U.S
    MS-Off Ver
    Excel 2007
    Posts
    25

    Formula to add a blank row if 2 values differ

    Hi all,

    I am trying to figure out a formula or code that will add a new, blank row in my sheet if the values in 2 cells are different. Also, could the code or formula highlight the blank row black or blue or something? Below is an example of what I need.

    Thanks for everyones time and help in advance.

    12345
    12345
    12345
    <-- need a new row added here
    12334
    12334
    <-- need a new row added here
    12234
    12234

    Thanks,

    Jeff

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Formula to add a blank row if 2 values differ

    Try this
    Option Explicit
    
    Sub x()
    
        Dim rRng As Range
        Dim Rw As Long
    
        With Sheet1
            Set rRng = Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp))
            For Rw = rRng.Rows.Count To 1 Step -1
                If Rw = 1 Then Exit For
                If .Cells(Rw, 1).Value <> .Cells(Rw - 1, 1).Value Then
                    .Cells(Rw, 1).EntireRow.Insert
                    With .Cells(Rw, 1).Interior
                        .ColorIndex = 33
                        .Pattern = xlSolid
                    End With
                End If
            Next Rw
        End With
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ 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