Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
For/Next with an If statement embedded
Try: If mybaseline = 10 Then Trend 'next macro exit for End If Tim. "Papa Jonah" wrote in message ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
CountIf embedded in an IF statement | Excel Worksheet Functions | |||
Create a formula that contains a complex embedded IF statement | Excel Worksheet Functions | |||
Need help with an embedded IF statement | Excel Worksheet Functions | |||
list embedded in an if statement | Excel Discussion (Misc queries) | |||
reducing the number of times an IF statement needs to be calculated in embedded IF statements | Excel Discussion (Misc queries) |