I'm getting the error Next without For in my following code can't figure out why:
I'm just copying the section of the code with the For loop. I'm using GoTo so that whenever a section of the code that's true is ran it will just go to the next i instead of running the subsequent sections that wouldn't apply once a section is true.
I'm just copying the section of the code with the For loop. I'm using GoTo so that whenever a section of the code that's true is ran it will just go to the next i instead of running the subsequent sections that wouldn't apply once a section is true.
VBA Code:
Dim lastrow As Long
Dim i As Integer
Dim AttainmentDysp As Double
Dim AttainmentFill As Double
Dim AttainmentTotInj As Double
Dim DyspMileOneAttainment As Double
Dim DyspMileTwoAttainment As Double
Dim FillMileOneAttainment As Double
Dim FillMileTwoAttainment As Double
lastrow = Sheets("Attainment").Cells(Rows.Count, 1).End(xlUp).Row
For i = 4 To lastrow
AttainmentDysp = Application.WorksheetFunction.Round(Sheets("Attainment").Cells(i, 6).Value, 3)
AttainmentFill = Application.WorksheetFunction.Round(Sheets("Attainment").Cells(i, 18).Value, 3)
AttainmentTotInj = Application.WorksheetFunction.Round(Sheets("Attainment").Cells(i, 30).Value, 3)
DyspMileOneAttainment = Application.WorksheetFunction.Round(Sheets("Attainment").Cells(i, 9).Value, 3)
DyspMileTwoAttainment = Application.WorksheetFunction.Round(Sheets("Attainment").Cells(i, 11).Value, 3)
FillMileOneAttainment = Application.WorksheetFunction.Round(Sheets("Attainment").Cells(i, 21).Value, 3)
FillMileTwoAttainment = Application.WorksheetFunction.Round(Sheets("Attainment").Cells(i, 23).Value, 3)
'MINIMUM 95% REQUIREMENT ON BOTH CATEGORIES CHECK
If AttainmentDysp + DyspContestMod < DyspQualMinReq Or AttainmentFill + FillContestMod < FillQualMinReq Then
Sheets("Attainment").Cells(i, 12).Value = 0
Sheets("Attainment").Cells(i, 24).Value = 0
Sheets("Attainment").Cells(i, 32).Value = "Y"
GoTo Last
End If
'IF 3 OR MORE MILESTONES MISSED CHECK
If MileCounter(i) <= 1 Then
Sheets("Attainment").Cells(i, 12).Value = 0
Sheets("Attainment").Cells(i, 24).Value = 0
Sheets("Attainment").Cells(i, 32).Value = "Y"
'Sheets("Attainment").Cells(i, 35).Value = MileCounter(i) FOR CHECK DELETE WHEN DONE
GoTo Last
End If
'BOTH CATEGORIES BELOW 100% CHECK
If AttainmentDysp + DyspContestMod < DyspQualReq And AttainmentFill + FillContestMod < FillQualReq Then
Sheets("Attainment").Cells(i, 12).Value = 0
Sheets("Attainment").Cells(i, 24).Value = 0
Sheets("Attainment").Cells(i, 32).Value = "Y"
GoTo Last
End If
'MULL CHECK'
Dim MileCount As Integer
MileCount = MileCounter(i)
If MileCount = 2 Then
TotInjMullAttain = Sheets("Standard Inputs").Range("H12").Value
ElseIf MileCount = 3 Then
TotInjMullAttain = Sheets("Standard Inputs").Range("I12").Value
ElseIf MileCount = 4 Then
TotInjMullAttain = Sheets("Standard Inputs").Range("J12").Value
If (MileCount < 4 Or _
(AttainmentDysp + DyspContestMod >= DyspMullAttainMin And AttainmentDysp + DyspContestMod < DyspQualReq) Or _
(AttainmentFill + FillContestMod >= FillMullAttainMin And AttainmentFill + FillContestMod < FillQualReq)) And _
MileCount >= 2 Then
If (AttainmentDysp + DyspContestMod >= DyspMullAttainMin And AttainmentFill + FillContestMod >= FillMullAttainMin) And _
AttainmentTotInj >= TotInjMullAttain Then
Sheets("Attainment").Cells(i, 12).Value = DyspPayout + Dysp2Payout
Sheets("Attainment").Cells(i, 24).Value = FillPayout + Fill2Payout
Sheets("Attainment").Cells(i, 32).Value = "Y"
Sheets("Attainment").Cells(i, 33).Value = "Y"
'BONUSES------------------------------------------------------------------------------------------------------------------------------------------------'
'When inputs at 0
If DyspBonusPayout = 0 And FillBonusPayout = 0 And DyspBonus2Payout = 0 And FillBonus2Payout = 0 Then
GoTo Last
End If
Dim TotalDyspBonus As Integer
Dim TotalFillBonus As Integer
TotalDyspBonus = DyspPayout + Dysp2Payout
TotalFillBonus = FillPayout + Fill2Payout
'D Bonuses
If DyspMileOneAttainment >= DyspBonusReq Then
TotalDyspBonus = TotalDyspBonus + DyspBonusPayout
Sheets("Attainment").Cells(i, 12).Value = TotalDyspBonus
End If
If DyspMileTwoAttainment >= DyspBonus2Req Then
TotalDyspBonus = TotalDyspBonus + DyspBonus2Payout
Sheets("Attainment").Cells(i, 12).Value = TotalDyspBonus
End If
'TF Bonuses
If FillMileOneAttainment >= FillBonusReq Then
TotalFillBonus = TotalFillBonus + FillBonusPayout
Sheets("Attainment").Cells(i, 24).Value = TotalFillBonus
End If
If FillMileTwoAttainment >= FillBonus2Req Then
TotalFillBonus = TotalFillBonus + FillBonus2Payout
Sheets("Attainment").Cells(i, 24).Value = TotalFillBonus
End If
GoTo Last
End If
End If
'ACC CHECKS
MileCount = MileCounter(i)
'Four Hits
If MileCount = 4 Then
Call FourHits(i)
ElseIf MileCount = 3 Then
Call ThreeHits(i)
ElseIf MileCount = 2 Then
Call TwoHits(i)
End If
Last:
Next i