Hi everyone, so I've been working at this problem for a while and can't get the code to produce exactly what I need.
I have a spreadsheet which is essentially going to print to an A4 sheet of 8 labels. On each label I want a customer name and order number, which is input via a UserForm. The UserForm also has a textbox for choosing how many labels you need printed on the sheet (trying to avoid waste instead of printing a full sheet every time when only 1 or 2 are needed).
So, I need the code to essentially loop through specific cells in the sheet (in columns B & D) and populate them with the respective client name or order number (I've gone with giving each type of cell a specific background color in order to target them). When I run the following code, it just populates all the cells, instead of just the quantity specified in the UserForm textbox.
Anyone got a) any clue where I'm going wrong and/or b) a more elegant solution please?
Many thanks, hope this makes sense!
I have a spreadsheet which is essentially going to print to an A4 sheet of 8 labels. On each label I want a customer name and order number, which is input via a UserForm. The UserForm also has a textbox for choosing how many labels you need printed on the sheet (trying to avoid waste instead of printing a full sheet every time when only 1 or 2 are needed).
So, I need the code to essentially loop through specific cells in the sheet (in columns B & D) and populate them with the respective client name or order number (I've gone with giving each type of cell a specific background color in order to target them). When I run the following code, it just populates all the cells, instead of just the quantity specified in the UserForm textbox.
Anyone got a) any clue where I'm going wrong and/or b) a more elegant solution please?
Many thanks, hope this makes sense!
VBA Code:
Private Sub PrintButton_Click()
Dim wb As Workbook: Set wb = ThisWorkbook
Dim labelSheet1 As Range
Dim colorCount As Integer
Set labelSheet1 = wb.Sheets("LabelSheet1").Range("B2:D9")
For Each cell In labelSheet1
If cell.DisplayFormat.Interior.Color = RGB(253, 253, 253) Then
colorCount = 1
Do Until colorCount > Me.BoxQuantity.Value
cell.Value = Me.DistributorName
colorCount = colorCount + 1
Loop
End If
If cell.DisplayFormat.Interior.Color = RGB(254, 254, 254) Then
colorCount = 1
Do Until colorCount > Me.BoxQuantity.Value
cell.Value = "#" & Me.OrderNumber
colorCount = colorCount + 1
Loop
End If
Next cell
Unload Me
End Sub