Can you help me understand this file, please?

regisfreitas

New Member
Joined
Mar 6, 2025
Messages
1
Office Version
  1. 365
  2. 2024
Platform
  1. Windows
Friends, I need a system that generates labels with volume control, and I found this one that meets my needs, but then comes the problem... when I click on GENERATE LABELS (GERAR ETIQUETAS), it only generates the label for the 18th line, and I don't understand why. I want it to generate from any line I indicate. Maybe the answer lies in the PANEL (PAINEL) button, but when I click it, a popup appears saying REFERENCE ISN'T VALID and it doesn't go anywhere. Could someone please try to help me with this? Thank you very much.

 
Welcome to the Forum!

It looks like the problem is with this loop. The values are being update for rows 8, 9, 10 ... 18, but the code isn't doing anything with them before the loop closes.

VBA Code:
For I = 8 To UltimaLinha    'where UltimaLinha is 18 in this case
    If Plan1.Cells(I, 19) <> "" Then
        Plan5.Cells(Lin, 1) = Plan1.Cells(I, 1)
        Plan5.Cells(Lin, 2) = Plan1.Cells(I, 2)
        Plan5.Cells(Lin, 3) = Plan1.Cells(I, 3)
        Plan5.Cells(Lin, 4) = Plan1.Cells(I, 4)
        Plan5.Cells(Lin, 5) = Plan1.Cells(I, 5)
        Plan5.Cells(Lin, 6) = Plan1.Cells(I, 6)
        Plan5.Cells(Lin, 7) = Plan1.Cells(I, 7)
        Plan5.Cells(Lin, 8) = Plan1.Cells(I, 8)
        Plan5.Cells(Lin, 9) = Plan1.Cells(I, 12)
        Lin = Lin + 1
    End If
Next

I haven't tested it, but it looks like you need to extend the loop like this:

Code:
    '...
    
    For I = 8 To UltimaLinha    'where UltimaLinha is 18 in this case
        If Plan1.Cells(I, 19) <> "" Then
            Plan5.Cells(Lin, 1) = Plan1.Cells(I, 1)
            Plan5.Cells(Lin, 2) = Plan1.Cells(I, 2)
            Plan5.Cells(Lin, 3) = Plan1.Cells(I, 3)
            Plan5.Cells(Lin, 4) = Plan1.Cells(I, 4)
            Plan5.Cells(Lin, 5) = Plan1.Cells(I, 5)
            Plan5.Cells(Lin, 6) = Plan1.Cells(I, 6)
            Plan5.Cells(Lin, 7) = Plan1.Cells(I, 7)
            Plan5.Cells(Lin, 8) = Plan1.Cells(I, 8)
            Plan5.Cells(Lin, 9) = Plan1.Cells(I, 12)
            Lin = Lin + 1
        End If
    
        'All other code dealing with Sheets("PREETIQUETAS") and Sheets("LAYOUT")

    Next UltimaLinha
    
    Application.ScreenUpdating = True

End Sub
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top