title: if function macro - results in a specific column
body: <p>I have a macro which uses if function. It places the results (1 or 0) to the column specified. However, I would like to specify the name of the column name. Let's say saying do the if function and bring the values to the column which header is called "Values". Below you can find the original code:</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 = "Values" Then FormulaCol = i
      If Cells(1, i).Value = "Test" Then LookupCol = i
  Next
  
  ActiveCell.FormulaR1C1 = "=IF(RC[-1]=""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 Sub
  </code></pre>
  
  <p>I know that this part of the code is responsible for static specified column:</p>
  
  <pre><code>ActiveCell.FormulaR1C1 = "=IF(RC[-1]=""United States"",1,0)"
  </code></pre>
  
  <p>But I don't know how I am suppose to change it to make it work as described above. Could someone help me with this?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here is the image showing what I want to achieve
  <img src="https://i.stack.imgur.com/szPvi.jpg" alt="enter image description here"></p>
  
  <p>Right now this macro works ok if the VALUE column is right to the TEST column. If the VALUE column is situated away from the test column, then it doesn't bring the proper values. I would like to make macro to look for the header "value" to identify where exactly value column is located (as for some files it won't be the same column) </p>
  
  <p>EDIT 2:
  Here is the result which I get using your current code. Even if I moved the VALUE column next to the TEST column it behaves the same. When using my code values were populated down from C2 to C9. As you can see using your code it brings the value in D1</p>
  
  <p><img src="https://i.stack.imgur.com/uYJIU.jpg" alt="enter image description here"> </p>