1

I have a piece of code in which i would like the for loop to continue to the next value of i if the value in a cell is "nil" and not execute the commands in the loop. I am unable to figure it out.

For i = 2 To n
    If .Cells(i, "G").Value = "nil" Then
        next i
    Else
        mon = month(.Cells(i, "G").Value)
        acctyp = .Cells(i, "P").Value
    end if
next i

Thanks in advance.

7
  • 1
    . . .i = i + 1 Commented Sep 24, 2018 at 7:45
  • 3
    Why is your current code not working? Commented Sep 24, 2018 at 7:50
  • since the variable mon is an integer i would not take in the month(nil) argument . Commented Sep 24, 2018 at 7:51
  • 3
    You really shouldn't need a GoTo statement in this though. The If should handle it Commented Sep 24, 2018 at 9:07
  • 1
    Your loop will work fine if you just remove the first Next i - replace it with a comment if that helps 'Do Nothing. Commented Sep 24, 2018 at 9:09

1 Answer 1

4

The comparison operator <> means "not equal to":

For i = 2 To n
    If .Cells(i, "G") <> "nil" Then
        mon = Month(.Cells(i, "G"))
        acctyp = .Cells(i, "P")
    End If
Next i
Sign up to request clarification or add additional context in comments.

1 Comment

@abinkurian - you're welcome . . . just to clarify, there are several comparison operators. Here is a list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.