• Application Defined Error (2003)

    Author
    Topic
    #447547

    hello and help

    I am playing around with the creation of a very simple version of Connect 4, namely, Connect 3. All seems well until a win is established which then throws up an error for which I can see no reason. Would someone look at the attached file and offer some explanation or even improvement.
    TIA

    Viewing 0 reply threads
    Author
    Replies
    • #1091785

      When someone wins, you call Reset. This makes A1 the active cell. After that, the code of CheckWin continues with the next test, but since A1 is now the active cell, ActiveCell(-1, 0) is not valid – it would be in row 0!

      The solution is either (1) to insert a line Exit Sub after each call to Reset, or (2) to use a series of ElseIfs:

      (1)

      If ActiveCell.Interior.ColorIndex = 5 And ActiveCell.Offset(-1, 1).Interior.ColorIndex = 5 And _
      ActiveCell.Offset(-2, 2).Interior.ColorIndex = 5 Then
      MsgBox “Blue wins!”
      reset
      Exit Sub
      End If

      or

      (2)

      If ActiveCell.Interior.ColorIndex = 5 And ActiveCell.Offset(-1, 1).Interior.ColorIndex = 5 And _
      ActiveCell.Offset(-2, 2).Interior.ColorIndex = 5 Then
      MsgBox (“Blue wins!”)
      reset
      ElseIf ActiveCell.Interior.ColorIndex = 5 And ActiveCell.Offset(-1, 0).Interior.ColorIndex = 5 And _
      ActiveCell.Offset(-2, 0).Interior.ColorIndex = 5 Then

    Viewing 0 reply threads
    Reply To: Application Defined Error (2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: