PDA

View Full Version : Insert Row when cell Value differs from above



Hankins
06-12-2007, 06:41 PM
I'd like to insert a row when my cell value differs from the above value. Please help.

Example

Shop
Shop
Field ====< Insert Row Here
Field
Field
Pipe=====< Insert Row Here
Pipe
Pipe
:p

lucas
06-12-2007, 06:56 PM
Try this for column B....change the B to the column you wish it to work on.
Option Explicit
Sub a()
Dim x As Long, LastRow As Long
' With Sheets("All Loans")
With ActiveSheet
LastRow = 3
For x = .Range("B65536").End(xlUp).Row To LastRow Step -1
If .Range("B" & x) <> .Range("B" & x - 1) Then .Rows(x).Insert
Next x
End With
End Sub

zv735
06-12-2007, 07:07 PM
Data on Column D
See Att. File



Sub InsertRow()
Dim i As Integer
Dim LastLine As Integer
LastLine = Range("D65536").End(xlUp).Row
For i = LastLine To 2 Step -1
If Range("D" & i).Value <> Range("D" & i - 1).Value Then
Rows(i & ":" & i).Insert Shift:=xlDown
End If
Next i
End Sub

lucas
06-12-2007, 07:45 PM
zv....I beat you to it by minutes....similar code..:devil2:
we must have been posting at the same time.

zv735
06-13-2007, 03:56 AM
Hello lucas

:rotlaugh:

With Regards