This is not how I would normally code this but as I can't fully understand what you finally want as a result. I have broken the code into several subs so that you can easily comment them out in the macro "Convert Sheet", or edit the individual subs.
The numbering you have asked for in "Line" seems to me, to be at odds with what you ask for in "Carton Label#".
Option Explicit
Sub ConvertSheet()
Dim LastRow As Long
Dim ws As Worksheet
On Error GoTo ResetApplication
Application.ScreenUpdating = False
Set ws = Sheets("Sheet1")
' Call the routines
LastRow = ws.Range("F" & Rows.Count).End(xlUp).Row
AddColumns ws, LastRow
RenumberLines ws, LastRow
AddRowsAndNumberNewRows ws, LastRow + 1
AddCartonLabels ws
ws.Range("A1").Select
ResetApplication:
Err.Clear
On Error GoTo 0
Application.ScreenUpdating = True
Set ws = Nothing
End Sub
Sub AddColumns(ws As Worksheet, LastRow As Long)
With ws
.Columns("H:H").Insert Shift:=xlToRight
.Range("H1") = "Carton Label#"
.Columns("H:H").Insert Shift:=xlToRight
.Range("H1") = "Case Number"
.Columns("H:H").Insert Shift:=xlToRight
.Range("H1") = "Carton (QTY.)"
.Range("H2").Resize(LastRow, 1).Formula = "=G2/12"
.Columns("H:J").AutoFit
End With
End Sub
Sub RenumberLines(ws As Worksheet, LastRow As Long)
Range("A2") = 1
Range("A3") = 2
Range("A2:A3").AutoFill Destination:=Range("A2:A" & LastRow), Type:=xlFillSeries
With Range("A2:A" & LastRow).Font
.ColorIndex = 3 'Red
.Bold = True
End With
End Sub
Sub AddRowsAndNumberNewRows(ws As Worksheet, LastRow As Long)
Dim RowNo As Long, RowsAdd As Long, NewLineNo As Long
With ws
For RowNo = LastRow To 3 Step -1
For RowsAdd = 1 To CInt(.Range("H" & RowNo - 1)) - 1
.Rows(RowNo).Insert Shift:=xlDown
Next
Next
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
NewLineNo = WorksheetFunction.Max(Range("A2:A" & LastRow)) + 1
For RowNo = 2 To LastRow
If .Range("A" & RowNo) = "" Then
.Range("A" & RowNo) = NewLineNo
.Range("A" & RowNo).Font.ColorIndex = 1
NewLineNo = NewLineNo + 1
End If
Next
End With
End Sub
Sub AddCartonLabels(ws As Worksheet)
Dim LastRow As Long
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
With ws.Range("J2")
.Resize(LastRow - 2, 1).Formula = "=" & Chr(34) & "Carton " & Chr(34) & "&ROW(A1)" & "&" & Chr(34) & " of " & LastRow - 2 & Chr(34)
.Resize(LastRow - 2, 1).Copy
.PasteSpecial xlPasteValues
End With
Application.CutCopyMode = False
ws.Columns("J:J").AutoFit
End Sub
"Sheet1" is a copy of your before sheet ("monkey"?), the code will convert "Sheet1"
To convert one of the sheets from your DDs' stuffed animals colection change ths line in the sub "ConvertSheet"
Set ws = Sheets("Sheet1")
e.g.
Set ws = Sheets("monkey")
Hope this helps
[EDIT]
If the line numbers are to be 1001, 1002, etc
Change these lines in Sub RenumberLines
Range("A2") = 1
Range("A3") = 2
To
Range("A2") = 1001
Range("A3") = 1002
Bookmarks