I have a code where I'm referencing variable "k" in a named range, and then performing a series of nested "if" loops. However, I can only put "next k" in one spot in the sub. However, I also need the code to loop back to the next k if certain conditions are met. In adding the 2nd "Next k" statement, I get the "Next Without For" error.
Here's the relevant code snippets:
Set SFR = SF.Range("a2", SF.Range("a2").SpecialCells(xlCellTypeLastCell))
Set Sheetparent = Control.Range("b2", Control.Range("b2").End(xlDown))
Set SheetControl = Control.Range("a2", Control.Range("a2").End(xlDown))
Set TypeControl = Control.Range("c2", Control.Range("c2").End(xlDown))
Set BDMControl = Control.Range("E2", Control.Range("e2").End(xlDown))
Set ParentControl = Control.Range("f2", Control.Range("f2").End(xlDown))
If r.Value = POp.Name Then
For Each k In SFR
If SFR(k.Row, 6).Value = r.Offset(0, 1).Value Then
For Each b In ParentControl
If SFR(k.Row, 1).Value = ParentControl(b.Row, 1).Offset(0, -1).Value Then
With POp.Range("a2")
.Offset(i, 0).Value = SFR(k.Row, 3).Value
.Offset(i, 1).Value = SFR(k.Row, 4).Value
.Offset(i, 2).Value = SFR(k.Row, 1).Value
.Offset(i, 3).Value = SFR(k.Row, 4).Value
.Offset(i, 4).Value = SFR(k.Row, 6).Value
.Offset(i, 5).Value = SFR(k.Row, 8).Value
.Offset(i, 6).Value = SFR(k.Row, 9).Value
.Offset(i, 7).Value = SFR(k.Row, 10).Value
.Offset(i, 8).Value = SFR(k.Row, 2).Value
.Offset(i, 9).Value = SFR(k.Row, 11).Value
.Offset(i, 10).Value = SFR(k.Row, 13).Value
.Offset(i, 11).Value = SFR(k.Row, 15).Value
End With
i = i + 1
Else
End If
Next b
Else
End If
Next k
Else
End If
So, the issue is that I get the same values SFR(k.row, [column]) repeated for several rows, before the formula moves on to the next SFR k. I want to be able to tell the macro to go to the next k if
If SFR(k.Row, 1).Value = ParentControl(b.Row, 1).Offset(0, -1).Value
Is true, and the values are copied over. Any suggestions? Thanks in advance.