Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello VBA guru,
I am new in VBA in Excel, and I was looking for a way to get row numbers of a filtered dataset. I mean, I have 1000 rows in my original dataset I filter them and I would like to get which rows are in the filtered dataset. I made a search in the ng but didn't find the solution. Since I manage to hack it, I would like to share it. Pls don't blame if the code is not optimized (as well as my english!), as I said I am newbe about it. MassimoM Public DefCriteriaRange As Variant Public filteredRows As New Collection ------------------------------------------- Private Sub btn_Filtra_Click() Dim filteredRange As Range Dim completeData As Range Set completeDataSet = Range("A13:X882") ' Filter using criteria defined in DefCriteriaRange variable completeDataSet.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range(DefCriteriaRange), Unique:=False ' get the range of filtered data using visible cell criteria Set filteredRange = completeDataSet.SpecialCells(xlVisible) ' Reset the collection For i = 1 To filteredRows.Count filteredRows.Remove (1) Next i ' get addresses of filtered rows addressesFilteredRows = completeDataSet.SpecialCells(xlVisible).Address ' split the addresses addressesSplitted = Split(addressesFilteredRows, ",") ' # of rows in the filtered range nFilteredRows = completeDataSet.Columns(1).SpecialCells(xlVisible) .Count - 1 ' get rows numebers For i = 1 To nFilteredRows filteredRows.Add Range(addressesSplitted(i)).Row Next i ' filteredRows contains the rows numbers as long. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Sum a Filtered List excluding Negative Numbers | Excel Discussion (Misc queries) | |||
How do I include filtered out numbers in a SUBTOTAL? | Excel Worksheet Functions | |||
counting unique numbers in filtered data | Excel Worksheet Functions | |||
Counting a Filtered Dataset | Excel Worksheet Functions | |||
creating a new dataset | Excel Programming |