View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Papa Jonah Papa Jonah is offline
external usenet poster
 
Posts: 148
Default For/Next with an If statement embedded

I have a condition that throws me into this loop. However I need to know how
to stop the loop per the If Then statement at the end.
Depending on how I have the ' marks, I either return to this sub-routine or
I get an error that says I have a next without a for.
Any advise would be appreciated.

Sub Mybaselinesub()
Dim i As Integer
For i = 2 To 5
Range("f3").FormulaR1C1 = "=DATE(YEAR(rc[1])-" & i & ",
MONTH(rc[1]), DAY(rc[1]))"

begbase = Range("f3").Value
Range("f3").Name = "begbase"
years = DateDiff("yyyy", begbase, reviewbeg)
Range("f4").Select
ActiveCell.FormulaR1C1 = "=match(r[-1]c,r[-2]c[-5]:r[" & numberrows
- 4 & "]c[-5],1)+2"
startbase = ActiveCell.Value
mybaseline = (endbase - startbase) + 1
If mybaseline = 10 Then
Trend 'next macro
'need to break the loop
'End Sub
End If

Next i

Trend 'next macro
End Sub