Hello. Try this code and see if it could help you.
Sub MoveCodeLine()
Dim countClass As Long, classLine As Long, codeLine As Long
Dim k As Long, x As Long, y As Long
Application.ScreenUpdating = False
countClass = Application.CountIf([A:A], "Class")
Do While k < countClass
classLine = [A:A].Find(what:="Class", after:=Cells(classLine + 1, 1)).Row
codeLine = [A:A].Find(what:="Code", after:=Cells(classLine, 1)).Row
Rows(codeLine).EntireRow.Copy
Rows(classLine).EntireRow.Insert
Rows(codeLine + 1).EntireRow.ClearContents
k = k + 1
Loop
x = 1
y = 1
Do
y = Cells(x, 1).End(xlDown).Row
x = Cells(y, 1).End(xlDown).Row
If Cells(x, 1).Value = "" Then Exit Sub
If x - y = 2 Then
Rows(x - 1).Insert
x = y + 3
ElseIf x - y > 3 Then
Range(Cells(y + 3, 1), Cells(x - 1, 1)).EntireRow.Delete
x = y + 3
End If
Loop
Application.ScreenUpdating = True
End Sub
Bookmarks