title: Excel VBA: concatenate formula with if condition
body: <p>I am trying to use the below coding to concatenate the cells based on criteria.. It throws me an syntax error. Can you please help me to correct this code or do I need to use a different method.</p>
  
  <p>Request:</p>
  
  <p><a href="https://i.stack.imgur.com/MRKO9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MRKO9.png" alt="enter image description here"></a></p>
  
  <p>Code:</p>
  
  <pre><code>Sub Conc()
  Dim lastrow As Range
  Dim str As String
  
  
  With Worksheets("sheet1")
  lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
  Range("F2").Select
  
  Range("F2:F" &amp; LastRow).Formula = "=IF(B2="aaa@to.com",CONCATENATE(E2," -",MID(A2,FIND("SECN",A2),14)),IF(B2&lt;&gt;"aaa@to.com",CONCATENATE(MID(A2,FIND("SECN",A2),14)," - ",C2)))"
  End With
  </code></pre>
  
  <p>End Sub</p>