Detect largest range of visible cells in a filtered range

eran85

New Member
Joined
Jul 3, 2014
Messages
2
I would like to be able to find the largest visible area of continuous rows in a filtered table. I know one possible way would be to loop through visible cells using the "xlCellTypeVisible" property and count cells in each visible area. However, the data is consisted of tens and sometimes hundreds of thousands of rows so I was wondering if there is a faster, more efficient way to do this.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
use subtotal after filtering. it subtotals on only visible data. for max it is 104

valuates hidden valuesIgnores hidden valuesFunction
1101AVERAGE()
2102COUNT()
3103COUNTA()
4104MAX()
5105MIN()
6106PRODUCT()
7107STDEV()
8108STDEVP()
9109SUM()
10110VAR()
11111VARP()

<tbody>
</tbody>
 
Upvote 0
Welcome to the MrExcel board!

Don't know exactly what you want to do with the range but with 200,000 rows filtered into about 50,000 different areas, this worked pretty quickly for me.
Rich (BB code):
Sub FindLargestArea()
  Dim r As Range, BigRange As Range
  Dim MaxRows As Long, AreaCount As Long
  
  For Each r In Range("A2", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlVisible).Areas
    AreaCount = AreaCount + 1
    If r.Rows.Count > MaxRows Then
      MaxRows = r.Rows.Count
      Set BigRange = r
    End If
  Next r
  MsgBox "Large range: " & BigRange.Address(0, 0) & vbLf & "Max rows: " & MaxRows & vbLf & "Number of areas checked = " & AreaCount
End Sub


Edit: Also not sure what you would want to do if there are multiple areas with the same (max) number of rows. This code will just report the first such one.
 
Last edited:
Upvote 0
Thanks for the answers.
Both solutions seem fine and I already implemented something similar to the second.
I wasn't aware of the "areas" property. great!
 
Upvote 0

Forum statistics

Threads
1,216,762
Messages
6,132,574
Members
449,737
Latest member
naes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top