PDA

View Full Version : [SOLVED] Help with For..Next Loop



Freshpetguy
04-16-2014, 09:45 AM
Hello and I'll thank you in advance for any help.
I am trying to do multiple checks in a couple of different loops
Loopctr moves down the column to check for the SKU and the formula number I need
Once I have the formula then I want to check column headings to see if that raw material number is present in the headings.
It starts at column 3 and then checks to see if the cell is empty, if so, then it will drop the raw material number in that cell.
If the raw material number equals the value in that cell, then I want it to move to the next cell to the right and check that one.
Issues:
I keep getting a syntax error on the "Continue For" statement

Anything else ya'all can help with would be appreciated.
Thanks,

MatlInfo:
Let MatlRow = 58
Let MatlCol = 1




MatlList:
MatlRow = MatlRow + 1



For loopctr = 59 To 96
Cells(loopctr, MatlCol).Select
If IsDate(CDate(ActiveCell.Value)) = True Then
DayofWeek = ActiveCell.Value
ActiveCell.Offset(0, 1).Select
SKU = ActiveCell.Value
Formula = Sheets("Schedule").Evaluate("Index($A$4:$P$54, Match(DayofWeek & SKU, $E$4:$E$54 & $A$4:$A$54, 0), 3)")
If Formula = "FR710 Fresh 2800" Then
MeatNo1 = Sheets("Schedule").Evaluate("Index('Bethlehem Master Complete Meals Recipe File.xlsx'!FR710Fresh2800,2,1)")
For i = 3 To 12
If IsEmpty(Cells(55, i)) Then Cells(55, i).Value = MeatNo1
If Cells(55, i).Value = MeatNo1 Then
Continue For
End If
Next
GoTo MatlList
Else
If ActiveCell.Value = 0 Then
GoTo MatlList
Else
SKU = ActiveCell.Value
MatlRow = MatlRow + 1
SKU = Cells(MatlRow, MatlCol).Value
End If
End If
Next loopctr

Bob Phillips
04-16-2014, 10:24 AM
There is no Continue, with your code you will probably need a GoTo (or rewrite it to remove the GoTos).

Freshpetguy
04-16-2014, 10:30 AM
Thank you for the input, but can I ask what you mean when you say, "There is no Continue"? Can you not use a "Continue For" statement if one of the conditions within the loop is met and you want to index to the next number?

Ago
04-16-2014, 11:06 AM
No you can't.

But as Xld said use goto.

Instead of continue for, have: goto continue
And on the row between end if and next loopctr, type continue:

Done.

Freshpetguy
04-16-2014, 11:13 AM
I get it. use the goto and mark the continue outside the loop to continue onto the next iteration. Okay, today we're teaching an old dog a new trick. Thanks, everyone, I'll give it a whirl.