title: Excel 2016 Vlookup Function in VBA
body: <p>I need some help with Excel's Vlookup function.
  I have 2 worksheets. On the first there's a Company Code, on the second I need to find values based on the company code. The relevant code is:</p>
  
  <pre><code>Dim Compcode, AUC, OB As String
  Dim WS1, WS2 As Worksheet
  Set WS1 = ThisWorkbook.Worksheets("Main Sheet")
  Set WS2 = ThisWorkbook.Worksheets("Data")
  Compcode = WS1.Cells(2, 1).Value 'Company code WS1 A2
  
  AUC = Application.WorksheetFunction.VLookup(Compcode, WS2.Range("A2:C30"), 2, False)
  OB = Application.WorksheetFunction.VLookup(Compcode, WS2.Range("A2:C30"), 3, False)
  </code></pre>
  
  <p>I've tried to modify the Dim for each of the variables and the Vlookup function itself, but I always get to the same error message:</p>
  
  <p>Run-time error '438': Object doesn't support this property or method</p>