title: Excel VBA - Custom Filter using Named Range
body: <p>I have a column of data on a worksheet, contained within a very large workbook that I am working on, named <code>Vendor</code> and I want to write a macro in VBA which allows me to filter by a particular vendor, say <code>Vendor A</code>.</p>
  
  <p>So far I have this:</p>
  
  <pre><code>Sub filterVendor()
  '
  ' filterVendor Macro
  '
  
  '
      ActiveSheet.Range("$A:$BB").AutoFilter Field:=21, Criteria1:= _
          "Vendor A"
  
  End Sub
  </code></pre>
  
  <p>The problem I have is that the location of the <code>Vendor</code> column may well change - as other columns are added and/or deleted before it, causing it to shift accordingly - and I want to know if it is possible to reference this particular column/block of data to save the macro becoming useless.</p>
  
  <p>Ideally, I would reference the range (<code>vendor</code> is what I would like to call the named range) so that, no matter what happens to the structure of the worksheet, the filter will always work correctly when the macro is run.</p>
  
  <p>How can this be done?</p>
  
  <p><strong>FURTHER INFO:</strong></p>
  
  <p>I suspect that the <code>Field:</code> criteria is causing the problem as this appears to absolutely define the column to be filtered; even though I have specified that the <code>Vendor</code> column is named <code>vendor</code> as a named range, and even though the named range reference moves along with said <code>Vendor</code> column, the column that is filtered always lies at the position specified in <code>Field:</code>.  How can this be fixed in order to work how I want it to?</p>
  
  <p>I have tried:</p>
  
  <pre><code>...Field:=Range("vendor")
  </code></pre>
  
  <p>and</p>
  
  <pre><code>...Field:=(Range("vendor"))
  </code></pre>
  
  <p>but both of these cause an error.</p>