Instead of
If Cells(x, 1).Value <> Cells(x + 1, 1).Value Then
Rows(x + 1).select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
you can use:
If Cells(x, 1).Value <> Cells(x + 1, 1).Value Then
Rows(x + 1).Resize(2).Insert
But if adding a simple column:
Private Sub test()
sn = Cells(1).CurrentRegion.Resize(, 1).Offset(, 9)
sq = Cells(1).CurrentRegion.Offset(, 1).Resize(, 5)
sq(1, 1) = 0
For j = 3 To UBound(sn) - 1
sq(1, 1) = sq(1, 1) + sq(j, 1)
If sq(j, 5) <> sq(j + 1, 5) Then
sn(j, 1) = sq(1, 1)
sq(1, 1) = 0
j = j + 1
End If
Next
Cells(1, 9).Resize(UBound(sn)) = sn
End Sub
Bookmarks