title: Wrong data type in WorksheetFunction.Filter
body: <p>I'm trying to make a function MonstersInLevel() that filters the second column of my &quot;LevelMonsters&quot; named range based on the value of the first column. The range's first column represents a game level ID and the second column represents a monster ID that appears in that level. <a href="https://i.stack.imgur.com/NVWX3.png" rel="nofollow noreferrer">Here's what my range looks like.</a></p>
  <p>If I call MonstersInLevel(2) I expect the function to return a range consisting of &quot;2&quot;, &quot;3&quot; and &quot;4&quot;.</p>
  <pre><code>Function MonstersInLevel(level As Integer) As Range
      MonstersInLevel = Application.WorksheetFunction.Filter(Range(&quot;LevelMonsters&quot;).Columns(2), Range(&quot;LevelMonsters&quot;).Columns(1) = level)
  End Function
  </code></pre>
  <p>I get:</p>
  <blockquote>
  <p>A value used in the formula is of the wrong data type</p>
  </blockquote>
  <p>I'm using the FILTER function as I would as an Excel formula. I assume there's some difference in the Excel and VBA syntax for FILTER's criteria.</p>