title: How to get full selection from Excel sheet using VBA without the filtered rows that are in between
body: <p>I am trying to get a selection from a worksheet in Excel using VBA, to use this selection as input for a next step of analysis on the data.
  This works fine, until you make a selection that has filtered rows in between. In that case it will only get the part of the range that is before the filtered rows.</p>
  
  <p>How can I also get the selected row(s) after the filtered rows?</p>
  
  <p>Below is the code that I use for getting the selected rows from the sheet, and an example of a selection where the code does not work as intended.</p>
  
  <pre><code>    For Each area In Selection.Areas
          Set newRange = area
          Set rnge = Selection.SpecialCells(xlCellTypeVisible)
          For i = 1 To rnge.Rows.Count
              x = rnge.Cells(i, 5).Value
              y = rnge.Cells(i, 6).Value
              Write #1, x, y
          Next i
      Next
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/s2OGc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s2OGc.png" alt="enter image description here"></a></p>
  
  <p>Update: using the code below, I got it to work, thanks to SNicolaou's answer</p>
  
  <pre><code>    Set rnge = Selection.SpecialCells(xlCellTypeVisible)
      For Each area In rnge.Areas
          For i = 1 To area.Rows.Count
              x = area.Cells(i, 5).Value
              y = area.Cells(i, 6).Value
              Write #1, x, y
          Next i
      Next
  </code></pre>