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..
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