G
Greg Maxey
I have a project where I need to sequentially number labels, based on a
starting/ending number in a UserForm. The labels are 80 to a sheet (Avery
5267) and the numbers need to run down and across. I have managed to cobble
together some code that will do this as long as I only need one sheet of
labels.
When I need more than 80 labels I add rows to my label template, however
with my current code the numbering continues down to the second and
subsequent pages of labels before starting across. A simplified version of
the code is provided below.
Can anyone offer a suggestion on how I could modify my code so that the
numbering would go down 20 and across to fill the first page of labels then
down 20 and across to fill the second page, etc.
Sub CreateNumberedLabels()
Dim i As Long
Dim j As Long
Dim seqStart As Long
Dim seqEnd As Long
Dim rowsCount As Long
Dim pStr As String
seqStart = InputBox("Enter starting number")
seqEnd = InputBox("Enter ending number")
pStr = "Happy Valley VFD" & vbCr & "Ticket ###"
rowsCount = ((seqEnd - seqStart) \ 4) + 1
If rowsCount > 20 Then
For i = 21 To rowsCount
ActiveDocument.Tables(1).Rows.Add
Next i
End If
Application.ScreenUpdating = False
For i = 1 To 7 Step 2
For j = 1 To ActiveDocument.Tables(1).Rows.Count
ActiveDocument.Tables(1).Cell(j, i).Range.Text = _
Replace(pStr, "###", Format(seqStart, "00#"))
seqStart = seqStart + 1
Next j
Next i
Application.ScreenUpdating = True
End Sub
Thanks
starting/ending number in a UserForm. The labels are 80 to a sheet (Avery
5267) and the numbers need to run down and across. I have managed to cobble
together some code that will do this as long as I only need one sheet of
labels.
When I need more than 80 labels I add rows to my label template, however
with my current code the numbering continues down to the second and
subsequent pages of labels before starting across. A simplified version of
the code is provided below.
Can anyone offer a suggestion on how I could modify my code so that the
numbering would go down 20 and across to fill the first page of labels then
down 20 and across to fill the second page, etc.
Sub CreateNumberedLabels()
Dim i As Long
Dim j As Long
Dim seqStart As Long
Dim seqEnd As Long
Dim rowsCount As Long
Dim pStr As String
seqStart = InputBox("Enter starting number")
seqEnd = InputBox("Enter ending number")
pStr = "Happy Valley VFD" & vbCr & "Ticket ###"
rowsCount = ((seqEnd - seqStart) \ 4) + 1
If rowsCount > 20 Then
For i = 21 To rowsCount
ActiveDocument.Tables(1).Rows.Add
Next i
End If
Application.ScreenUpdating = False
For i = 1 To 7 Step 2
For j = 1 To ActiveDocument.Tables(1).Rows.Count
ActiveDocument.Tables(1).Cell(j, i).Range.Text = _
Replace(pStr, "###", Format(seqStart, "00#"))
seqStart = seqStart + 1
Next j
Next i
Application.ScreenUpdating = True
End Sub
Thanks