title: Vlookup execution criteria
body: <p>How can I modify the execution of the vlookup based upon a specific value.  I want it to execute the Vlookup only if the output sheet (sheet 2) cell (Q2 to AB2) contains &quot;Forecast&quot; otherwise skip column if labeled &quot;Actual&quot; in the relative cell.</p>
  <p>Finally I want to copy and paste any cells in the Column Q to AB that contain the vlookup forumla.  I believe this can be accomplished using the String function.</p>
  <pre><code>Sub MakeFormulas()
  Dim SourceLastRow As Long
  Dim OutputLastRow As Long
  Dim sourceSheet As Worksheet
  Dim outputSheet As Worksheet
  Dim X As Long
  
  'names of our worksheets
  Set sourceSheet = Worksheets(&quot;Sheet1&quot;)
  Set outputSheet = Worksheets(&quot;Sheet2&quot;)
  
  
  'Determine last row of source
   With sourceSheet
   SourceLastRow = .Cells(.Rows.Count, &quot;A&quot;).End(xlUp).Row
  End With
  With outputSheet
  
  'Determine last row in col C
   OutputLastRow = .Cells(.Rows.Count, &quot;C&quot;).End(xlUp).Row
  
  For X = 2 To OutputLastRow
  If InStr(1, .Range(&quot;C&quot; &amp; X), &quot;PO Materials&quot;) + InStr(1, .Range(&quot;C&quot; &amp; X), &quot;PO Labor&quot;) &gt; 0 Then
      'Apply  formula
  .Range(&quot;Q&quot; &amp; X &amp; &quot;:AB&quot; &amp; X).Formula = _
  &quot;=VLOOKUP($E&quot; &amp; X &amp; &quot;,'&quot; &amp; sourceSheet.Name &amp; &quot;'!$A$2:$L$&quot; &amp; SourceLastRow &amp; &quot;,Match(Q$1,'&quot; &amp;    sourceSheet.Name &amp; &quot;'!$A$1:$AD$1,0),0)&quot;
  End If
  Next
   End With
   End Sub
  </code></pre>
  <h3>Sheet 2 Screenshot</h3>
  <p><img src="https://i.stack.imgur.com/SAczh.jpg" alt="screenshot" /></p>