title: Manipulating Ranges in Excel - Returning a Value (Error 2029)
body: <p>I am a quite new to Excel VBA, and I come from a more... traditional programming background (Java, C). I am having issues with passing a Range Object as a parameter in my User-defined function (see below). The idea of my function is to take several parameters to complete a VLOOKUP of a filtered range. </p>
  
  <p>I may have several syntax issues (I am unsure of my return type and my usage of VLOOKUP), and I would appreciate some guidance on this. See results, more information in my code:</p>
  
  <pre><code>Public Function GETVALUE(screen As String, strEvent As String, dataRange As Range, strDate As String) As String
  
  'ASSUMPTION: dataRange has three columns; first column contains lookup values; Second
  ' column contains dates for filtering; Third column contains return values
  
  Dim result As String
  
  'remove irrelevant dates in dataRange; apply filter
  'ASSUMPTION: This process should return a Range that is removes all Rows that does
  'not have strDate in the second column
  Dim newRange As Range
  
  'RESULT: Returns #VALUE!. I know this is not the typical := syntax I see in many 
  'examples but this one apparently compiles, so I use it. I comment this line out 
  'and try to make the other lines below work with dummy parameters or fixed ranges
  newRange = dataRange.AutoFilter(2, strDate)
  
  'Now I try to use the newly filtered, "newRange" and use that in my VLOOKUP
  'and return it.
  result = [VLOOKUP("*" &amp; screen &amp; "/" &amp; strEvent &amp; "*", newRange, 3, False)]
  
  'I can see an Error 2029 here on Result
  GETVALUE = result 
  'RESULT: Returns #VALUE!
  End Function
  </code></pre>