Getting Loop without Do error

mdd16

Board Regular
Joined
Jan 11, 2011
Messages
84
Office Version
  1. 365
Platform
  1. Windows
Can someone help.. why am I getting Loop without Do error..

should be simple stuff .. but I can't get my head around it after going up and down.. *looping 😂" through it several times..
VBA Code:
Sub MakeLables_AHU()
Dim qAHU_Tot, qLamp, qAHU, nAHU, qLamp1, qLamp2, qLamp3 As Integer
Dim Lamp_aofb, AhuTagTxt, Lamp1, Lamp2, Lamp3, LampSizeTxt As String

Sheets("LabelPr_Ahu").Select

Sheets("LabelPr_Ahu").Range("LblAHU_TabBeg").Offset(0, 0).Select

qAHU_Tot = Sheets("Main page").Range("WO_AhuQty").Value

x = 1 ' SNo. of AHU in list
'total number of AHUs in current row
Do ' loop for next AHU Via X
qAHU_Row = Sheets("AHU Data").Range("TabBeg").Offset(x, 5).Value

Lamp1 = Sheets("AHU Data").Range("TabBeg").Offset(x, 7).Value
Lamp2 = Sheets("AHU Data").Range("TabBeg").Offset(x, 9).Value
Lamp3 = Sheets("AHU Data").Range("TabBeg").Offset(x, 11).Value

qLamp1 = Sheets("AHU Data").Range("TabBeg").Offset(x, 8).Value
qLamp2 = Sheets("AHU Data").Range("TabBeg").Offset(x, 10).Value
qLamp3 = Sheets("AHU Data").Range("TabBeg").Offset(x, 12).Value


    ' Sno. of AHU for which labels are being made
    nAHU = 1 ' = first AHU of qAHU_Row
    
    Do ' Loop for next nAHU in same row via nAHU
         'SNo. of lamp qty = First Lamp
        qLamp = qLamp1 + qLamp2 + qLamp3
        Z = 0
        Do 'Loop for Next Lamp. Via Z
            Z = Z + 1
            
            'write AHU Name on Label Sheet
            If qAHU_Row = 1 Then
                AhuTagTxt = Sheets("AHU Data").Range("TabBeg").Offset(x, 1).Value
            Else
                AhuTagTxt = Sheets("AHU Data").Range("TabBeg").Offset(x, 1).Value _
                    & " (" & nAHU & ")"

            End If
            
            Selection.Offset(Z, 0).Value = AhuTagTxt
            
            'write part No. of Label Sheet
            Selection.Offset(Z, 1).Value = Sheets("AHU Data").Range("TabBeg").Offset(x, 2)
            
            'write WO No on label sheet
            Selection.Offset(Z, 2).Value = _
                Sheets("Main Page").Range("WoNo").Offset(0, 0).Value
                
            'Create Lamp Size Text
            If qLamp2 = 0 Then
                LampSizeTxt = Lamp1
            ElseIf qLamp2 > 0 And qLamp3 = 0 Then
                If Z > qLamp1 Then
                    LampSizeTxt = Lamp2
                Else: LampSizeTxt = Lamp1
                End If
            
            ElseIf qLamp2 > 0 And qLamp3 > 0 Then
                If Z > qLamp2 Then
                    LampSizeTxt = Lamp3
                ElseIf Z >= qLamp2 And Z < qLamp3 Then
                    LampSizeTxt = Lamp2
                Else: LampSizeTxt = Lamp1
                
            End If
            
             'write lamp label
            Lamp_aofb = Z & " of " & qLamp & " (" & LampSizeTxt & ")"
            Selection.Offset(Z, 3).Value = Lamp_aofb
            
            'Z = Z + 1 'next lamp for AHU
        Loop Until Z = qLamp
        
        Selection.Offset(qLamp, 0).Select
        
        nAHU = nAHU + 1
    
    Loop Until nAHU = qAHU_Row + 1

    x = x + 1
    qAHU_Row = Sheets("AHU Data").Range("TabBeg").Offset(x, 5).Value
    
Loop Until x = qAHU_Tot + 1


End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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