title: VBA code with if function (values taken from the cell)
body: <p>I have VBA code which uses countif function and checks if the value "United States" is populated in the Test column <em>(see the code below)</em>.</p>
  
  <p>I would like to make this more flexible and I want it to get the data from the specific column (e.g. A2) instead of static value "United States". </p>
  
  <p>I know that this piece of code should be amended</p>
  
  <pre><code>Debug.Print "=IF(RC[" &amp; CStr(FormulaCol - LookupCol - 1) &amp; "]=""United States"",1,0)"
  ActiveCell.Offset(0, FormulaCol - 1).FormulaR1C1 = "=IF(RC[" &amp; CStr(LookupCol -     FormulaCol) &amp; "]=""United States"",1,0)"
  </code></pre>
  
  <p>I tried to use the simple function code =IF(B2=A2,1,0) and put A2 in the code. All my tries returned the syntax error.</p>
  
  <p><strong>My Macro</strong></p>
  
  <pre><code>Sub bbb()
  Dim FormulaCol As Long
  Dim LookupCol As Long
  Dim TotalRows As Long
  Dim TotalCols As Long
  Dim i As Long
  
  Sheets("Sheet1").Select
  TotalRows = ActiveSheet.UsedRange.Rows.Count
  TotalCols = ActiveSheet.UsedRange.Columns.Count
  
  For i = 1 To TotalCols
  If Cells(1, i).Value = "Test" Then
      LookupCol = i
      Exit For
  End If
  Next
  
  For i = 1 To TotalCols
  If Cells(1, i).Value = "Values" Then
      FormulaCol = i
      Range("A2").Activate
      Debug.Print "=IF(RC[" &amp; CStr(FormulaCol - LookupCol - 1) &amp; "]=""United States"",1,0)"
      ActiveCell.Offset(0, FormulaCol - 1).FormulaR1C1 = "=IF(RC[" &amp; CStr(LookupCol - FormulaCol) &amp; "]=""United States"",1,0)"
      Cells(2, FormulaCol).AutoFill Destination:=Range(Cells(2, FormulaCol), Cells(TotalRows, FormulaCol))
      With Range(Cells(2, FormulaCol), Cells(TotalRows, FormulaCol))
      .Value = .Value
      End With
  End If
  Next
  End Sub
  </code></pre>