end if without block if

  • Thread starter Thread starter Dirk Nachbar
  • Start date Start date
D

Dirk Nachbar

This is a very eay macro and yet Excel complains about an "end if
without block if". Why???

Sub check()

Count = 0
For i = 1 To 9
For j = 1 To 9
If Cells(i + 3, j + 3) <> Cells(i + 26, j + 26) Then Do
Cells(i + 3, j + 3).Select
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
Count = Count + 1
End If
Next j
Next i


If Count > 0 Then MsgBox (Count & "are still wrong")
If Count = 0 Then MsgBox ("You have solved it")
End Sub
 
I'm not sure what the purpose of "Do" is in your code. Try it without. And
I prefer to space out the block if's and with's to make for easier reading
and debugging.

Sub check()

Count = 0
For i = 1 To 9
For j = 1 To 9
If Cells(i + 3, j + 3) <> Cells(i + 26, j + 26) _
Then
Cells(i + 3, j + 3).Select
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
Count = Count + 1
Else
End If
Next j
Next i


If Count > 0 Then MsgBox (Count & "are still wrong")
If Count = 0 Then MsgBox ("You have solved it")
End Sub


HTH,
Paul
 
yes it was the DO, thanks

Dirk

I'm not sure what the purpose of "Do" is in your code. Try it without. And
I prefer to space out the block if's and with's to make for easier reading
and debugging.

Sub check()

Count = 0
For i = 1 To 9
For j = 1 To 9
If Cells(i + 3, j + 3) <> Cells(i + 26, j + 26) _
Then
Cells(i + 3, j + 3).Select
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
Count = Count + 1
Else
End If
Next j
Next i

If Count > 0 Then MsgBox (Count & "are still wrong")
If Count = 0 Then MsgBox ("You have solved it")
End Sub

HTH,
Paul









- Show quoted text -
 

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

Back
Top