I'm pretty new to VBA and I've searched as best as I can but I still can't find an answer. I need to write a Macro that will insert a new line based on multiple conditions. The rows have to be in groups no larger than 5 and separated by carrier. But if a Container is repeating, it counts as 1 row.
Current:
Container Carrier
ABC56 Carrier 1
XOS752 Carrier 1
IOW45 Carrier 1
WOFJ74 Carrier 1
NMC85 Carrier 1
DDJD7 Carrier 1
DFF789 Carrier 1
DFF789 Carrier 1
CSGS Carrier 1
GSW132 Carrier 1
WYWI78 Carrier 1
WTS758 Carrier 1
MNV74 Carrier2
ADS78 Carrier2
CTDS45 Carrier2
CTDS45 Carrier2
LHKGL78 Carrier2
XJSS772 Carrier2
XJSHS7 Carrier2
OIJS7 Carrier2
Desired:
ABC56 Carrier 1
XOS752 Carrier 1
IOW45 Carrier 1
WOFJ74 Carrier 1
NMC85 Carrier 1
DDJD7 Carrier 1
DFF789 Carrier 1
DFF789 Carrier 1
CSGS Carrier 1
GSW132 Carrier 1
WYWI78 Carrier 1
WTS758 Carrier 1
MNV74 Carrier2
ADS78 Carrier2
CTDS45 Carrier2
CTDS45 Carrier2
LHKGL78 Carrier2
XJSS772 Carrier2
XJSHS7 Carrier2
OIJS7 Carrier2
I will take any direction you have! I have these two codes separately. One Separates by Carrier and One Separates into 5 row increments. However, It doens't have all the logic built in.
To separate into groups of 5:
Option Explicit
Sub InsertIT()
Dim x As Integer
x = 1 'Start Row
Do
Range("A" & x, "B" & x).Insert
x = x + 6
Loop
End Sub
To separate by Carrier:
Sub InsertRowAtChangeInValue()
For lRow = Cells(Cells.Rows.Count, "B").End(xlUp).Row To 2 Step -1
If Cells(lRow, "B") <> Cells(lRow - 1, "B") Then Rows(lRow).EntireRow.Insert
Next lRow
End Sub