title: Excel VBA Userform QueryClose: Cancel not working
body: <p>I've written the code below so that it will check if a process has been completed or not before closing the form. This userform is used as a scoresheet that will make <code>range("A6")</code> green to signify a pass, or <code>range("B6")</code> red to signify a fail as the final step of the sub, before unloading the form. </p>
  
  <p>From what I've checked online so far, it should be working. While debugging, the macro gets all the way to where it says Cancel = True, reads over the line, but the form closes anyway.</p>
  
  <p>Why isn't the cancel registering even when it reads over the line?</p>
  
  <pre><code>Private Sub Userform_queryclose(CloseMode As Integer, Cancel As Integer)
  Dim wbScoreCard As Workbook
  Dim wsScoreCard As Worksheet
  Dim MSG As String
  Set wbScoreCard = Workbooks(NameBox.Value)
  Set wsScoreCard = wbScoreCard.Worksheets(Format(Date, "MM.dd.yy") &amp; " " &amp; CallType.Caption)
  If Err.Number = 0 Then
      If wsScoreCard.Range("A6").Interior.Color &lt;&gt; vbGreen Then
          If wsScoreCard.Range("B6").Interior.Color &lt;&gt; vbRed Then
              Beep
              MSG = MsgBox("This scorecard is not complete! If you close it now, this scorecard will not be saved. Continue?", vbYesNo, "Warning - Scorecard Incomplete")
              If MSG = vbYes Then
                  wbScoreCard.Close savechanges:=False
                  Exit Sub
              Else
                  Cancel = True
                  Exit Sub
              End If
          End If
      End If
  End If
  End Sub
  </code></pre>