Jerry Paladino
asked on
VBA to Delete the Filtered Rows in an Excel Table
Requesting help with the VBA to delete the filtered rows from an Excel Table. I do not want to delete the entire row but only the row in the table. I understand the code below will delete the hidden table rows but it also deletes the entire row which I want to avoid. Only the table row should be deleted.
Thank You - Jerry
Filtered-Table.xlsm
For Each rw In [Tbl_Mstr].Rows
If rw.Rows.Hidden Then
rw.Rows.Delete
End If
Next rw
Sample file with a filtered table is attached. The Table name is "Tbl_Mstr".Thank You - Jerry
Filtered-Table.xlsm
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Rgonzo1971,
After working with this for a bit, may I suggest replacing the lines that reference Range("A1") with a table reference in the event the table being acted upon is located elsewhere on the worksheet.
Jerry
After working with this for a bit, may I suggest replacing the lines that reference Range("A1") with a table reference in the event the table being acted upon is located elsewhere on the worksheet.
If Not rng Is Nothing Then
[Tbl_Mstr[#Headers]].CurrentRegion.AutoFilter
rng.Delete shift:=xlShiftUp
[Tbl_Mstr[#Headers]].CurrentRegion.AutoFilter
End If
Or, alternately...
If Not rng Is Nothing Then
Range("Tbl_Mstr[#Headers]").CurrentRegion.AutoFilter
rng.Delete shift:=xlShiftUp
Range("Tbl_Mstr[#Headers]").CurrentRegion.AutoFilter
End If
Again - Thank you for your help!Jerry
ASKER
Works great! I appreciate your help.
Thank You - Jerry