Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CountIf embedded in an IF statement Amber Excel Worksheet Functions 8 July 30th 07 07:44 PM
Create a formula that contains a complex embedded IF statement Tom Excel Worksheet Functions 1 May 18th 07 06:38 PM
Need help with an embedded IF statement Lari Excel Worksheet Functions 8 June 17th 06 04:59 PM
list embedded in an if statement rk0909 Excel Discussion (Misc queries) 0 March 14th 06 03:45 PM
reducing the number of times an IF statement needs to be calculated in embedded IF statements Harold Good Excel Discussion (Misc queries) 4 November 17th 05 06:36 PM


All times are GMT +1. The time now is 12:07 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"