Next without for

S

Sally Mae

I have macro that contains among other thing o for loop. I now get error next
without for. I cannot see what the problem is. My code:
For l = 1 To i - 1
If rng6.Offset(l, 0) <> 0 Then
If rng4.Offset(l, 0) = 0 Then
Range(rng1.Offset(l, k + 3).Address) = rng3.Offset(l, 0)
* Range(rng1.Offset(l, k + 1).Address)
Else: Range(rng1.Offset(l, k + 3).Address) = rng4.Offset(l,
0) * Range(rng1.Offset(l, k + 1).Address)
End If
Else: Range(rng1.Offset(l, k + 3).Address) = rng3.Offset(l, 0) *
Range(rng1.Offset(l, k + 1).Address)
End If
dblSummaSecurityContributionToBench =
dblSummaSecurityContributionToBench + Range(rng1.Offset(l, k + 3).Address)


'kollar om det finns skillnad i local return mellan bench och portfölj
If rng4.Offset(l, 0) <> 0 And rng3.Offset(l, 0) <> 0 And rng4.Offset(l,
0) <> rng3.Offset(l, 0) Then
dblLocalReturnDiff = rng4.Offset(l, 0) - rng3.Offset(l, 0)
If Abs(dblLocalReutrnDiff) > dblErrorMarginal Then
Err.Raise 600
Else: End If
Next

as you can see there are several if´s in the for-loop, but that has never
been a problem before. Please help me if you know what is wrong! Thank you!
 
B

Bob Phillips

You are missing an End If.

Better laying out of the code makes it clearer

For l = 1 To i - 1
If rng6.Offset(l, 0) <> 0 Then
If rng4.Offset(l, 0) = 0 Then
Range(rng1.Offset(l, k + 3).Address) = rng3.Offset(l, 0) * _
Range(rng1.Offset(l, k + 1).Address)
Else
Range(rng1.Offset(l, k + 3).Address) = rng4.Offset(l, 0) * _
Range(rng1.Offset(l, k + 1).Address)
End If
Else
Range(rng1.Offset(l, k + 3).Address) = rng3.Offset(l, 0) * _
Range(rng1.Offset(l, k + 1).Address)
End If
dblSummaSecurityContributionToBench = _
dblSummaSecurityContributionToBench + _
Range(rng1.Offset(l, k + 3).Address)

'kollar om det finns skillnad i local return mellan bench och portfölj
If rng4.Offset(l, 0) <> 0 And rng3.Offset(l, 0) <> 0 And _
rng4.Offset(l, 0) <> rng3.Offset(l, 0) Then
dblLocalReturnDiff = rng4.Offset(l, 0) - rng3.Offset(l, 0)
If Abs(dblLocalReutrnDiff) > dblErrorMarginal Then
Err.Raise 600
End If
End If
Next



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

Sally Mae said:
I have macro that contains among other thing o for loop. I now get error next
without for. I cannot see what the problem is. My code:
For l = 1 To i - 1
If rng6.Offset(l, 0) <> 0 Then
If rng4.Offset(l, 0) = 0 Then
Range(rng1.Offset(l, k + 3).Address) = rng3.Offset(l, 0)
* Range(rng1.Offset(l, k + 1).Address)
Else: Range(rng1.Offset(l, k + 3).Address) = rng4.Offset(l,
0) * Range(rng1.Offset(l, k + 1).Address)
End If
Else: Range(rng1.Offset(l, k + 3).Address) = rng3.Offset(l, 0) *
Range(rng1.Offset(l, k + 1).Address)
End If
dblSummaSecurityContributionToBench =
dblSummaSecurityContributionToBench + Range(rng1.Offset(l, k + 3).Address)


'kollar om det finns skillnad i local return mellan bench och portfölj
If rng4.Offset(l, 0) <> 0 And rng3.Offset(l, 0) <> 0 And rng4.Offset(l,
0) <> rng3.Offset(l, 0) Then
dblLocalReturnDiff = rng4.Offset(l, 0) - rng3.Offset(l, 0)
If Abs(dblLocalReutrnDiff) > dblErrorMarginal Then
Err.Raise 600
Else: End If
Next

as you can see there are several if´s in the for-loop, but that has never
been a problem before. Please help me if you know what is wrong! Thank
you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top