title: VBA Go to the next filtered cell
body: <p>I am currently using the following code:</p>
  
  <pre><code>Sub SendEmail()
  
      Dim objOutlook As Object
      Dim objMail As Object
      Dim RowsCount As Integer
      Dim Index As Integer
      Dim Recipients As String
      Dim Category As String
      Dim CellReference As Integer
  
      Set objOutlook = CreateObject("Outlook.Application")
      Set objMail = objOutlook.CreateItem(0)
  
      If ActiveSheet.FilterMode = True Then
          RowsCount = ActiveSheet.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count - 1
      ElseIf ActiveSheet.FilterMode = False Then
          RowsCount = Application.CountA(Range("A2:A" &amp; Rows.Count)) - 1
      End If
  
      ' In Range("I1") there is the job category the user wants to email
      Category = Range("I1")
      If Category = Range("S2") Then
          ' CellReference is the amount of columns to the right of column A, ie Column A is 0 so CellReference below is J - which is the column location of the email address according to that category
          CellReference = 10
      ElseIf Category = Range("S3") Then
          CellReference = 14
      ElseIf Category = Range("S4") Then
          CellReference = 18
      ElseIf Category = Range("S5") Then
           CellReference = 16
      End If
  
      Index = 0
      While Index &lt; RowsCount
          Set EmailAdrs = ActiveSheet.AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Cells(1, CellReference).Offset(0 + Index, 0)
          Recipients = Recipients &amp; EmailAdrs.Value &amp; ";"
          Index = Index + 1
      Wend
  
       With objMail
          .To = Recipients
          .Subject = "This is the subject"
          .Display
      End With
  
      Set objOutlook = Nothing
      Set objMail = Nothing
  
  End Sub
  </code></pre>
  
  <p>This code checks to see if a filter has been applied and counts the amounts of rows if there is one or isn't one, it then checks to see who should be emailed (the 'Category' which is in <code>I1</code> is the job position of different individuals) and then gets the email addresses of those required, the issue I'm having is say I have the following data (this is just an example of what I want to do):</p>
  
  <pre><code>Column A         Column B             Column C
  Smith            Male                 123@123.co.uk
  Jones            Male                 abc@abc.co.uk
  Smith            Female               456@123.co.uk
  Jones            Female               def@abc.co.uk
  Smith            Male                 789@123.co.uk
  Smith            Female               101112@123.co.uk
  Smith            Female               141516@123.co.uk
  Jones            Female               ghi@abc.co.uk
  </code></pre>
  
  <p>And I filter on <code>Jones</code> in column A and <code>Female</code> in Column B to get two rows returned, rather than getting the email addresses <code>def@abc.co.uk</code> and <code>ghi@abc.co.uk</code> it will get the email addresses <code>def@abc.co.uk</code> and <code>789@123.co.uk</code> because it finds the first row with the filter applied then goes to the next cell disregarding the filter.</p>
  
  <p>Is there a way I can fix this so that it gets the filtered cells?</p>
  
  <p>It is important to point out that the filter may not always be the same, so it won't always be both Column A and Column B, it might just be Column A or just Column B.</p>