title: Formulas within a macro VBA
body: <p>Hello I'm a total beginner in terms of coding i just took a semester course in excel so I apologize for being this broken
  I'm trying to make a button macro that when pressed takes the typed out ID from a certain cell, copies it to a running master list on a different sheet, and then references a table on through index match on a different sheet and use that to insert a specific date (anniversary of hire +1 or +2 years based on how many days off they have remaining). Hopefully you can get an idea of my intentions from my elementary code starting with setting variables</p>
  <pre><code>    Private Sub Submitsp3_Click()
   Dim a As Long
   Dim b As Integer
   Dim c As Integer
   a = Range(&quot;M8&quot;).FormulaR1C1 = &quot;=INDEX(Employee_List[[#All],[Days Since Hire]],MATCH(R[0]C[-9],Employee_List[[#All],[ID '#]],0))&quot;
   b = Range(&quot;M8&quot;).FormulaR1C1 = &quot;=INDEX(Employee_List[[#All],[Days left]],MATCH(R0C0,Employee_List[[#All],[ID '#]],0))&quot;
   Sheets(&quot;employee info&quot;).Select
  </code></pre>
  <p>then a bunch of conditions</p>
  <pre><code>If a &lt; 90 Then
  MsgBox (&quot;This employee does not yet have access to paid days off&quot;)
  ElseIf b = 0 Then
  MsgBox (&quot;This employee is out of paid off days&quot;)
  Dim answer As Integer
  answer = MsgBox(&quot;Do you want to Continue?&quot;, vbQuestion + vbYesNo)
  ElseIf answer = vbNo Then
  MsgBox &quot;Macro Ending&quot;
  ElseIf answer = vbYes Then
  '''bunch of copy and pasting things around'''
  </code></pre>
  <p>lastly the part to put in the correct date</p>
  <pre><code>Sheets(&quot;raw list of dates off&quot;).Range(&quot;D3&quot;).Select
       c = Range(&quot;A3&quot;).FormulaR1C1 = &quot;=INDEX(Employee_List[[#All],[Days left]],MATCH(R0C0,Employee_List[[#All],[ID '#]],0))&quot;
  If c &lt; 6 Then
     ActiveCell.Formula = &quot;=EDATE([@[Hire date]],12*INT(YEARFRAC([@[Hire date]],TODAY())+2))&quot;
  ElseIf c &lt; 6 Then
     ActiveCell.Formula = &quot;=EDATE([@[Hire date]],12*INT(YEARFRAC([@[Hire date]],TODAY())+1))&quot;
  End If
     Sheets(&quot;employee info&quot;).Select
      MsgBox (&quot;Date added&quot;)
      End Sub
  </code></pre>
  <p>my question is, it does seem like I'm doing any of this correctly. The current issue is that it always pulls up the first message in the code. Then gives an error 1004 and then highlights the &quot;Sheets(&quot;raw list of dates off&quot;).Range(&quot;D3&quot;).Select&quot;</p>