title: comparing a single value against an array in VBA
body: <pre><code>Sub CHECKas()
      Dim lastrow As Long
      Dim lastcol As Long
      Dim l As Integer
      Dim i As Integer
      Dim rname As Constants
      Set rngTarg = Selection
      lastrow = Sheets("report").Range("B" &amp; Rows.Count).End(xlUp).row
      lastcol = Sheets("report").Cells(2, Columns.Count).End(xlToLeft).Column
      Sheets("FEBBRAIO").Select
      ActiveCell.Offset(0, -3).Copy
      Sheets("REPORT").Select
      Cells(1, lastcol + 1).PasteSpecial xlPasteAll
      Application.CutCopyMode = False
      rname = Application.ActiveCell.Value
      ActiveCell.Offset(1, 0).Select
  
      For i = 2 To lastrow
          ThisWorkbook.Sheets("report").Select
          If Range("f2:f" &amp; lastrow) &lt;= Val(CStr(rname.Value)) _
              And Range("g2:g" &amp; lastrow) &gt; Val(CStr(rname.Value)) Then
  
              Cells(i, ActiveCell.Column).Value = "1"
  
          Else
  
              Cells(i, ActiveCell.Column).Value = 0
  
          End If
  
      Next i
  End Sub
  </code></pre>
  
  <p>I'm new in VBA and I can't understand how to compare a constant value with each cell in a <code>range("g2:g" &amp; lastrow)</code> and <code>("f2:f" &amp; lastrow)</code>. The constant value is an active cell in my case. For example considering this formula: <code>IF(AND($R$1&lt;G2;$R$1&gt;=f2);1;0</code> where <code>R$1$</code> is the active cell of the last not empty column in ROW 1. I need to fill the entire column (that is <code>activecell.column</code>) with the output coming out form this formula.</p>
  
  <p>But the I Got mismatch error in:</p>
  
  <pre><code>If Range("f2:f" &amp; lastrow) &lt;= Val(CStr(rname.Value)) _
      And Range("g2:g" &amp; lastrow) &gt; Val(CStr(rname.Value)) Then
      Cells(i, ActiveCell.Column).Value = "1"
  Else
      Cells(i, ActiveCell.Column).Value = 0
  End If
  </code></pre>
  
  <p>I know from the previous question that this error occurs because I'm trying to comparing a single value against an array of values. How can fix this problem?</p>