title: VBA - if cell is empty then skip the sub
body: <p>I have code, which put formula into area and it works fine:</p>
  
  <pre><code>Private Sub Jeeves_account2_C()
  
  Dim lastrow As Long
  Dim rng As Range, C As Range
  
  With Worksheets("Crd_Headers") ' &lt;-- here should be the Sheet's name
      lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row ' last row in column B
      Set rng = .Range("C2:C" &amp; lastrow) ' set the dynamic range to be searched
  
      ' loop through all cells in column B
      For Each C In rng
          If Not IsEmpty(C.Value) Then
              C.Offset(, -1).Formula = "=IFERROR(VLOOKUP(RC[2],Jeeves_Cust_list!C[-1]:C[1],3,0),RC[2])" ' use offset to put the formula in column "P"
          End If
      Next C
  End With
  
  End Sub
  </code></pre>
  
  <p>But I would like to add condition, if cell C2 on the sheet Crd_Headers is empty, then skip the whole sub:</p>
  
  <pre><code>If Worksheets("Crd_Headers").Cells("C2") = "" Then
      Exit Sub
  End If
  </code></pre>
  
  <p>So the code looks like:</p>
  
  <pre><code>Private Sub Jeeves_account2_C()
  
  If Worksheets("Crd_Headers").Cells("C2") = "" Then
      Exit Sub
  End If
  
  Dim lastrow As Long
  Dim rng As Range, C As Range
  
  With Worksheets("Crd_Headers") ' &lt;-- here should be the Sheet's name
      lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row ' last row in column B
      Set rng = .Range("C2:C" &amp; lastrow) ' set the dynamic range to be searched
  
      ' loop through all cells in column B
      For Each C In rng
          If Not IsEmpty(C.Value) Then
              C.Offset(, -1).Formula = "=IFERROR(VLOOKUP(RC[2],Jeeves_Cust_list!C[-1]:C[1],3,0),RC[2])" ' use offset to put the formula in column "P"
          End If
      Next C
  End With
  
  End Sub
  </code></pre>
  
  <p>But it gives me error message <strong>invalid procedure call or argument</strong></p>
  
  <p>Could you advise me, what do I do wrong?</p>
  
  <p>Thank you!</p>