0

Stupid question: This code isn't compiling correctly, and I can't find a solution on any of the other "Next without For" questions. I have a feeling I'm just missing something stupid. Here's the relevant code:

 For Each Cell In CHWAssigned
    If Cell = "" Then
        If Cell.Row Mod 3 = 0 Then
            Cell.Value = "DM"
        ElseIf Cell.Row Mod 3 = 1 Then
            Cell.Value = "CWS"
        ElseIf Cell.Row Mod 3 = 2 Then
            Cell.Value = "CF"
    Else
    End If
Next Cell

I think I've closed all of the If statements, but there must be one in there that's open. Thanks for taking the time to address something so simple.

3
  • 4
    You have two Ifs but only one End If ... Commented Oct 20, 2017 at 15:02
  • you haven't closed the last ElseIf, control falls to an Else which is within a parent If block. Commented Oct 20, 2017 at 15:03
  • Perfect, thanks! Just noticed it right when you commented Commented Oct 20, 2017 at 15:03

1 Answer 1

1

You are missing and End if, your code should work now. You don't need to specify Cell in the Next statement. Also you can use Case instead of ElseIf.

For Each Cell In CHWAssigned
   If Cell = "" Then
       If Cell.Row Mod 3 = 0 Then
          Cell.Value = "DM"
       ElseIf Cell.Row Mod 3 = 1 Then
          Cell.Value = "CWS"
       ElseIf Cell.Row Mod 3 = 2 Then
          Cell.Value = "CF"
       End If
    End If
Next

Hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

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.