Looping through a table with hidden rows

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
721
Office Version
  1. 2016
Platform
  1. Windows
When a Table is declared, is there something else that I need to do to loop through filter rows?

VBA Code:
                        With ws5
                            .ListObjects(1).AutoFilter.ShowAllData
                            .ListObjects("Table1").Range.AutoFilter 1, dlr, xlFilterValues
                            .ListObjects("Table1").Range.AutoFilter 2, dept, xlFilterValues
                            lr4 = .Cells(.Rows.Count, 1).End(xlUp).Row
                            For r = 2 To lr4
                                If .Rows(r).Hidden = True Then Debug.Print r 'Confirming if row r is hidden
                                If .Rows(r).Hidden = False Then eto = .Cells(r, 6) & ";" & eto
                            Next r
                        End With

lr4 = 76 rows, however, based on the filter applied only one row shows up, and that is row 2, row 1 being my header.

What I don't understand is the loop is adding the data in each .Cells(r,6) from 2-76. Based on the applied filter only row 2 is visible. I would assume from my code only data from .Cells(2,6) would be applied to eto.

What am I missing? Thank you.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
I would assume from my code only data from .Cells(2,6) would be applied to eto.
.. so what *is* happening if not that?

What worksheet row are the table headers in?
 
Upvote 0
.. so what *is* happening if not that?

What worksheet row are the table headers in?
the loop is looping through all rows, visible or invisible. My code clearly states "If .Rows(r).Hidden = False Then"

"row 1 being my header"
 
Upvote 0
I had two issues going on:
1st - I didn't notice I had a loop inside another loop - I need to be better organized.
2nd - I think using ListObjects(1) and ListObjects("Table1") was causing trouble.
Before -
VBA Code:
                            .ListObjects(1).AutoFilter.ShowAllData
                            .ListObjects("Table1").Range.AutoFilter 1, dlr, xlFilterValues
                            .ListObjects("Table1").Range.AutoFilter 2, dept, xlFilterValues
After -
VBA Code:
    Set lo = ws5.ListObjects(1)
                With ws5
                    lo.AutoFilter.ShowAllData
                    lo.Range.AutoFilter 1, dlr, xlFilterValues
                    lo.Range.AutoFilter 2, dept, xlFilterValues
                    lr4 = .Cells(.Rows.Count, 1).End(xlUp).Row
                    For r = 2 To lr4
                        If .Rows(r).Hidden = False Then eto = .Cells(r, 6) & ";" & eto
                    Next r
                End With
 
Upvote 0
Seems like you have it sorted now then?
 
Upvote 0

Forum statistics

Threads
1,214,598
Messages
6,120,441
Members
448,966
Latest member
DannyC96

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