Previously i have a macro guided by you, i want to print based on column I(Sheet Master Data) but there is a situation where i will having multiple duplicate Length number can the macro exclude the duplicate and remain the below Macro function to choose how many sticker i wanted to print. I have attached a sample as above
Sub GenerateStickers()
Dim w1 As Worksheet
Dim w2 As Worksheet
Dim r As Long
Dim m As Long
Dim s As Long
Dim i As Long
Dim n As Long
n = Val(InputBox(Prompt:="How many copies of each sticker do you want?", Default:=1))
If n < 0 Then
Beep
Exit Sub
End If
Set w1 = Worksheets("Master Data")
Set w2 = Worksheets("Barcode Sticker")
w2.Range("12:" & w2.Rows.Count).Clear
w2.PageSetup.PrintArea = "B2:C11"
m = w1.Range("A" & w1.Rows.Count).End(xlUp).Row
s = 2
For r = 2 To m
For i = 1 To n
w2.Range("B2:D11").Copy Destination:=w2.Range("B" & s)
w2.Range("C" & s + 6).Value = w1.Range("D" & r).Value
w2.Range("B" & s + 8).Resize(2, 2).Merge Across:=True
s = s + 10
Next i
Next r
m = s - 1
For s = 12 To m Step 10
w2.HPageBreaks.Add Before:=w2.Range("A" & s)
Next s
w2.PageSetup.PrintArea = "B2:C" & m
w2.ExportAsFixedFormat Type:=xlTypePDF, Filename:="Barcode.pdf"
End Sub
You do not have the required permissions to view the files attached to this post.
I don't understand - in the workbook that you have attached, the Barcode Sticker sheet consists of a single merged cell. The result will look terrible.
Thanks. You didn't even bother to adjust the code to copy the length...
Will the data always be sorted on length (column I)?
If not, would it be OK if the code sorts it on length?
Option Explicit
Sub GenerateStickers()
Dim w1 As Worksheet
Dim w2 As Worksheet
Dim r As Long
Dim m As Long
Dim s As Long
Dim i As Long
Set w1 = Worksheets("Master Data")
Set w2 = Worksheets("Barcode Sticker")
w2.Range("12:" & w2.Rows.Count).Clear
w2.PageSetup.PrintArea = "B2:C11"
m = w1.Range("A" & w1.Rows.Count).End(xlUp).Row
For r = 2 To m
s = 20 * r - 38
For i = 1 To 2
w2.Range("B2:D11").Copy Destination:=w2.Range("B" & s + 10 * (i - 1))
w2.Range("B").Value = w1.Range("I" & r).Value
Next i
Next r
m = s + 19
For s = 12 To m Step 10
w2.HPageBreaks.Add Before:=w2.Range("A" & s)
Next s
w2.PageSetup.PrintArea = "B2:C" & m
w2.ExportAsFixedFormat Type:=xlTypePDF, Filename:="Barcode.pdf"
End Sub