title: VBA - Comparison anomalies using variant
body: <p>I have found a couple of other questions dealing with variants but none of them seem to address my issue.</p>
  
  <p>I have very simple for loops doing comparisons. The purpose is to color the Excel cell red if there isn't a match. The results are 99% accurate, but I have noticed a couple of seemingly random errors. For example, a cell containing the number 104875 is not colored red, which indicates that there should be a matching cell in the comparison column. But there isn't. It seems like they should all be wrong or all be correct. Some of the other threads about variants have mentioned that the comparisons have to be of the same type or you will get weird errors. In my case, they are of the same type (both integers), so this isn't the problem.</p>
  
  <p>I am brand new to VBA and still trying to understand how it works.</p>
  
  <p>This is the relevant part of the code:</p>
  
  <pre><code>Private Sub CommandButton1_Click()
  
  Dim i As Long, j As Long
  Dim flag As Boolean
  Dim array1() As Variant, array2() As Variant
  Dim column1 As Double
  Dim column2 As Double
  
  column1 = convertColumn(TextBox1.Text)
  column2 = convertColumn(TextBox2.Text)
  
  Set wb1 = Workbooks("Advocate July 2017 Data.xlsm").Sheets(1)
  Set wb2 = Workbooks("BI Report 8-18-17.xlsm").Sheets(1)
  
  array1 = Intersect(wb1.Columns(column1), wb1.UsedRange)
  array2 = Intersect(wb2.Columns(column2), wb2.UsedRange)
  
  
  For i = 2 To UBound(array1)
      flag = False
      For j = 2 To UBound(array2)
          If IsNumeric(array1(i, 1)) And IsNumeric(array2(j, 1)) Then If CDbl(array1(i, 1)) = CDbl(array2(j, 1)) Then flag = True
          Next j
      If Not flag Then wb1.Cells(i, column1).Interior.Color = vbRed
  Next i
  End Sub
  </code></pre>
  
  <p>EDIT: Turns out that my code works fine. The problem was simply that some of the cells on one of the sheets were hidden and I didn't realize it. ~facepalm~ that's what I get for being inexperienced in excell</p>