title: For Loop Ignores True IF Condition When ELSE Is Present
body: <p>It would appear that I have an issue with getting my For Loop to acknowledge I have a <code>True</code> <code>IF</code> condition, when an <code>ELSE</code> condition exists in the loop body. Here's what I've written:</p>
  
  <pre><code> Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  
      'TEST FIND/SEARCH FEATURES
      Dim String2Find As String = txtCPUSerial.Text
      Dim ColumnNumber As Integer = 1
  
      'Access the worksheet
      Dim xlApp As Excel.Application
      xlApp = CreateObject("Excel.Application")
      xlApp = GetObject(, "Excel.Application")
  
      Dim xlWB As Excel.Workbook = xlApp.Workbooks.Open("C:\Users\Machine\Desktop\DocDirectory\MyDoc.xls") 
  
      Dim xWS As Excel.Worksheet
  
      xWS = xlWB.Worksheets("Sheet1")
  
      'TRY TO LOOP THROUGH THE ROWS..
  
       For x As Integer = 1 To xWS.Rows.Count Step 1
  
          'Check if cell value matches the search string...
          If xWS.Cells(x, ColumnNumber).value = String2Find Then
              MessageBox.Show("Got it..." &amp; String2Find &amp; " in row " &amp; x)
  
          Else
              MessageBox.Show("Item not in the sheet...")
  
              Exit For
          End If
      Next
  
  End Sub
  </code></pre>
  
  <p>I've tried writing a straight statement in my <code>Else</code> where the <code>String2Find &lt;&gt; txtCPUSerial.Text</code>, but either the syntax blows up, or I'm still getting the message dialog for <strong>"Item not in the sheet..."</strong>, thus the True portion of my For Loop gets ignored while stepping through, and won't return dialog upon getting a <code>True</code> condition. </p>
  
  <p>If I remove my <code>Else</code>, then obviously the code loops accordingly and will return the text, if the textbox value does exists in my sheet (I've written an arbitrary value in the sheet to find. What am I not including or specifying that's causing this to occur?</p>