I have the For Next statement working to sum all numbers up to value of n, but when I try and accomplish the same thing with Do While Loop and Do Until Loops I get iteration errors that crash my excel. I want the code to continue to work for the ElseIf of summing only even numbers to n and only odd numbers to n, but I'm wondering if it is an issue with the way I typed it or if these loops can't go within the IF statement.
If optsa.Value = True Then
Cells(6, 4) = "Sum All"
sum = 0
i = 0
For i = 0 To n Step 1
sum = sum + i
Cells(8 + i, 2) = i
Cells(8 + i, 3) = sum
Next i
lblfn.Caption = sum
'Do While Sum All
sum = 0
i = 0
step = 0
Do While i <= n
sum = sum + i
step = step + 1
Cells(8 + step, 4) = sum
i = i + 1
Loop
lbldw.Caption = sum
'Do Until Sum All
sum = 0
i = 0
step = 0
Do Until i > n
sum = sum + i
step = step + 1
Cells(8 + step, 5) = sum
i = i + 1
Loop
lbldu.Caption = sum
'ElseIf etc
End If
Bookmarks