Sub printlabel()
Dim palletno As Long
Dim nolabels As Long
Dim stopprint As Long
Dim palletprefix As String
Dim labellength As Long
labellength = Len(Range("A15").Value)
If labellength = 10 Then
palletprefix = Left(Range("A15").Value, 9)
palletno = Val(Right(Range("A15").Value, 1))
nolabels = InputBox("Enter no. of pallet labels")
ElseIf labellength = 9 Then
palletprefix = Left(Range("A15").Value, 8)
palletno = Val(Right(Range("A15").Value, 1))
nolabels = InputBox("Enter no. of pallet labels")
Else
Exit Sub
End If
stopprint = 0
Do Until stopprint = nolabels Or palletno = 9
Range("A15:A17").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
stopprint = stopprint + 1
palletno = palletno + 1
Range("A15").Value = palletprefix & palletno
Loop
If labellength = 10 Then
palletprefix = Left(Range("A15").Value, 8)
palletno = Right(Range("A15").Value, 2)
Else 'assuming labellength = 9
palletprefix = Left(Range("A15").Value, 7)
palletno = Val(Right(Range("A15").Value, 2))
nolabels = InputBox("Enter no. of pallet labels")
End If
Do Until stopprint = nolabels Or palletno = 99
Range("A15:A17").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
stopprint = stopprint + 1
palletno = palletno + 1
Range("A15").Value = palletprefix & palletno
Loop
If labellength = 10 Then
palletprefix = Left(Range("A15").Value, 7)
palletno = Right(Range("A15").Value, 3)
Else 'assuming labellength = 9
palletprefix = Left(Range("A15").Value, 6)
palletno = Val(Right(Range("A15").Value, 3))
nolabels = InputBox("Enter no. of pallet labels")
End If
Do Until stopprint = nolabels Or palletno = 999
Range("A15:A17").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
stopprint = stopprint + 1
palletno = palletno + 1
Range("A15").Value = palletprefix & palletno
Loop
If labellength = 10 Then
palletprefix = Left(Range("A15").Value, 6)
palletno = Right(Range("A15").Value, 4)
Else 'assuming labellength = 9
palletprefix = Left(Range("A15").Value, 5)
palletno = Val(Right(Range("A15").Value, 4))
nolabels = InputBox("Enter no. of pallet labels")
End If
Do Until stopprint = nolabels Or palletno = 9999
Range("A15:A17").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
stopprint = stopprint + 1
palletno = palletno + 1
Range("A15").Value = palletprefix & palletno
Loop
If labellength = 10 Then
palletprefix = Left(Range("A15").Value, 5)
palletno = Right(Range("A15").Value, 5)
Else 'assuming labellength = 9
palletprefix = Left(Range("A15").Value, 4)
palletno = Val(Right(Range("A15").Value, 5))
nolabels = InputBox("Enter no. of pallet labels")
End If
Do Until stopprint = nolabels Or palletno = 99999
Range("A15:A17").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
stopprint = stopprint + 1
palletno = palletno + 1
Range("A15").Value = palletprefix & palletno
Loop
If labellength = 10 Then
palletprefix = Left(Range("A15").Value, 4)
palletno = Right(Range("A15").Value, 6)
Else 'assuming labellength = 9
palletprefix = Left(Range("A15").Value, 3)
palletno = Val(Right(Range("A15").Value, 6))
nolabels = InputBox("Enter no. of pallet labels")
End If
Do Until stopprint = nolabels Or palletno = 999999
Range("A15:A17").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
stopprint = stopprint + 1
palletno = palletno + 1
Range("A15").Value = palletprefix & palletno
Loop
If labellength = 10 Then
palletprefix = Left(Range("A15").Value, 3)
palletno = Right(Range("A15").Value, 7)
Else
Exit Sub
End If
Do Until stopprint = nolabels Or palletno = 9999999
Range("A15:A17").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
stopprint = stopprint + 1
palletno = palletno + 1
Range("A15").Value = palletprefix & palletno
Loop
End Sub