title: Write Variable To Cell In VBA
body: <p>I am needing to follow the protocol below:<br>
  I am scanning Sheet1 and for each unique empName on that worksheet selecting the individual empName worksheet.<br>
  on the individual empName worksheet capturing the value in the last cell in column O<br>
  Storing the value in variable tper (it's a percentage)<br>
  Selecting sheet1<br>
  Writing a header to column N1<br>
  Selecting the 1st empty cell in column N (excluding the header)<br>
  write the value of tper to the selected cell in column N<br>
  Repeat until all empNames have been processed from Sheet1<br></p>
  
  <p>My syntax seems to execute as it should up until this line <code>lr1 = Cells(Rows.Count, 13).End(xlUp).Row</code> where it throws an error of </p>
  
  <blockquote>
    <p>error invalid qualifier</p>
  </blockquote>
  
  <p>What do I need to re-write in order for this to follow the protocol outlined above?</p>
  
  <pre><code>Function Test()
  Dim lr As Long, i As Long, lr1 As Long, i1 As Long
  Dim WS As Worksheet, empName As String, tper As Variant
  
  Set WS = ActiveSheet
  lr = Cells(Rows.Count, 2).End(xlUp).Row
  For i = 2 To lr
    empName = WS.Cells(i, 2).Value
    Sheets(empName).Select
    tper = "=LOOKUP(2,1/(O:O&lt;&gt;""),O:O)"
    Sheets("Sheet1").Select
    Range("N1").FormulaR1C1 = "Percent"
    lr1 = Cells(Rows.Count, 13).End(xlUp).Row
    For i1 = 2 To lr1
      lr1.Cells.FormulaR1C1 = tper
    Next i1
  Next i
  End Function
  </code></pre>