title: VBA IF Then Vlookup Multiple Sheet
body: <p>I am trying to retrieve data from another file using the VLOOKUP function however this is only to happen depending on if any of the 2 items of data appear in column 3(C)</p>
  
  <p>"PO Materials"  OR
  "PO Labor"</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
  
  'What are the names of our worksheets?
  Set sourceSheet = Worksheets("Sheet1")
  Set outputSheet = Worksheets("Sheet2")
  
  
  'Determine last row of source
  With sourceSheet
      SourceLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
  End With
  
  With outputSheet
  
      'Determine last row in col C
      OutputLastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
  
      For X = 5 To OutputLastRow
          If InStr(1, .Range("C" &amp; X), "PO Materials") &gt; 0 Then
              'Apply our formula
          .Range("Q2:Q" &amp; OutputLastRow).Formula = _
              "=VLOOKUP(E2,'" &amp; sourceSheet.Name &amp; "'!$A$2:$B$" &amp; SourceLastRow &amp; ",2,0)"
          End If
      Next
  End With
  
  End Sub
  </code></pre>
  
  <p>Code is working; However, its giving #N/A if the cell is blank or contains any value in Column C, which means its not recognizing the If statement.  If the column does not containn "PO Materials" or "PO Labor" I would like it to skip to the next cell in the range</p>
  
  <p>Thanks in advance for any help given.</p>