Need macro to compare cells, insert row

Microsoft Office excel 2007 home & stude...
January 5, 2011 at 14:18:34
Specs: Windows XP
Hello all,

Using Excel 2007. I have two columns, and need to compare the two columns and if the numbers are the same, insert a cell above the mismatched cell in Column B. Been trying for hours to figure it out on my own. Any help would be greatly appreciated.

Bonus round: There's a third column that needs to be bumped down along with the mismatched number in column B. Example:

Data:
A B C
1 1 x
1 1 x
1 2 x
1 1 x

Result:
A B C
1 1 x
1 1 x
1
1 2 x
1 1 x

Thanks so much in advance.


See More: Need macro to compare cells, insert row

Report •

#1
January 10, 2011 at 15:31:04
Try this...

Sub InsertAtDifference()
 lastRw = Range("A" & Rows.Count).End(xlUp).Row
  For rw = 1 To lastRw
   If Cells(rw + 1, 2) <> Cells(rw, 2) Then
    Cells(rw + 1, 2).EntireRow.Insert
    Cells(rw + 1, 1) = Cells(rw - 1, 1)
    rw = rw + 2
   End If
  Next
End Sub

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •
Related Solutions


Ask Question