going to next i on certain condition

Lavina

Board Regular
Joined
Dec 18, 2018
Messages
75
Hey guys,

i have a piece of code that is throwing an error: next i without for at the NextIteration part
Code:
For i = 2 To lastRow
variableInQuestionReal = Range("L" & i)
variableInQuestionDecimal = GetDecimal(Range("L" & i), False)
If isError(variableInQuestionReal) = true Then GoTo NextIteration
If variableInQuestionDecimal < 0.9 Then variableInQuestionInt = WorksheetFunction.Floor(variableInQuestionReal, 1)
If variableInQuestionDecimal > 0.9 Then variableInQuestionInt = WorksheetFunction.Ceiling(variableInQuestionReal, 1)
Range("O" & i).Value = variableInQuestionInt
Next i
Exit Sub
NextIteration:
Next i
I'm trying to make a manual rounding function and sometimes my data is missing values. I was hoping to just skip over the whole cycle if the value is wrong. Fixing this problem here is easy, but i was wondering how could i stop and skip a part of the cycle if a condition is met?
 
Last edited:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
You can't have 2 'Next i's

I don't see why you would because you are close to the solution as you already have 'NextIteration'

If you still struggle, please post the full sub as it's confusing why you have 'Exit Sub'
 
Upvote 0
Code:
For i = 2 To lastRow
    variableInQuestionReal = Range("L" & i)
    variableInQuestionDecimal = GetDecimal(Range("L" & i), False)
    If IsError(variableInQuestionReal) = True Then
        If variableInQuestionDecimal < 0.9 Then variableInQuestionInt = WorksheetFunction.Floor(variableInQuestionReal, 1)
        If variableInQuestionDecimal > 0.9 Then variableInQuestionInt = WorksheetFunction.Ceiling(variableInQuestionReal, 1)
    End If
Range("O" & i).Value = variableInQuestionInt
Next i
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,927
Messages
6,122,311
Members
449,080
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top