title: VBA Autofilter With Multiple Criteria Using Variables
body: <p>EDIT: To fix the issue, I changed <code>Dim Placed As Range</code> to <code>As Long</code>. I then changed </p>
  
  <pre><code>Set Placed = Rows("3:3").Find("Placed", Range("A3"), searchdirection:=xlToRight)
  </code></pre>
  
  <p>to</p>
  
  <pre><code>Placed = Rows("3:3").Find("Placed", Range("A3"), searchdirection:=xlToRight).Column
  </code></pre>
  
  <p>The code works just fine now.
  END EDIT</p>
  
  <p>Ok, I've been working on this issue for almost two hours now.</p>
  
  <p>I'm trying to code a couple of option buttons on a worksheet to filter the data as needed.</p>
  
  <p>To begin, I recorded myself filtering the data to give me a starting point. This is what the recorder spit out:</p>
  
  <pre><code>ActiveSheet.Range("$A$3:$CS$212").AutoFilter Field:=53, Criteria1:=Array( _
      "Iteration 1", "Iteration 2", "Iteration 3", "Tradeshow", "="), Operator:= _
      xlFilterValues
  </code></pre>
  
  <p>To make the option buttons more robust, I decided to use variables just in case columns or rows were added, or if criteria were added.</p>
  
  <p>I added a variable for the <code>Range()</code>, <code>Field:=</code>, and <code>Criteria1:=</code>, but my code throws this error now: <code>Run-time error '1004': Autofilter Method of Range class failed</code>.</p>
  
  <p>I'm wondering if I'm using the <code>Array</code> improperly...? Anyway, here are my declarations:</p>
  
  <pre><code>Const Opt1 As String = "Iteration 1"
  Const Opt2 As String = "Iteration 2"
  Const Opt3 As String = "Iteration 3"
  Const Opt4 As String = "Iteration 4"
  Const Opt5 As String = "Tradeshow"
  Const Opt6 As String = "Placed"
  
  Dim Placed As Range             'This is the Field var.
  Dim lastRow, lastColumn As Long 'Holds the last row and column numbers.
  Dim Rng1, Rng2 As Range         'These hold the beginning and ending ranges for the filter
  </code></pre>
  
  <p>And here's how I'm setting my variables:</p>
  
  <pre><code>lastRow = Range("A:A").Find("*", Range("A1"), searchdirection:=xlPrevious).Row
  lastColumn = Cells(3, Columns.Count).End(xlToLeft).Column
  Set Placed = Rows("3:3").Find("Placed", Range("A3"), searchdirection:=xlToRight)
  Set Rng1 = Cells(3, 1)
  Set Rng2 = Cells(lastRow, lastColumn)
  </code></pre>
  
  <p>Finally, here is the <code>AutoFilter</code> code:</p>
  
  <pre><code>ActiveSheet.Range(Rng1, Rng2).AutoFilter Field:=Placed, Criteria1:=Array(Opt1, Opt2, Opt3, Opt4, Opt5, Opt6, "="), Operator:=xlFilterValues
  </code></pre>
  
  <p>Does anyone see why it might be throwing that error? Does it have something to do with the <code>Array</code>? Any help will be much appreciated!</p>