Need to use AutoFilter on multiple tables within a single VBA code

mallandroid

New Member
Joined
Jan 12, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I have created a very simple VBA code that automatically applies a filter on the single column I have filtered on a table, which I have named “BB.Tbl1”. However, I want the VBA to apply to multiple tables that are all on the same worksheet, so I want it to include my other tables named "BB.Tbl2" and "BB.Tbl3", and those tables are the exact same design and also have a single filter on the same column. My code works only for the first table, and it currently looks like this:

Private Sub Worksheet_Change(ByVal Target As Range)

Me.Range("BB.Org1").ListObject.AutoFilter.ApplyFilter

End Sub

Let me know how I can update the VBA to work for all 3 tables. Thanks!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I ended up solving the issue here. It appears that pointing to the "Me" object was causing the problem for me. By removing "Me" as the parent object at the beginning of the syntax, it allowed me to continue to repeat this code ad infintum for as many tables as I would need. So for example, the following VBA code now allows me to automatically re-apply filters to the 3 tables in my worksheet:

Private Sub Worksheet_Change(ByVal Target As Range)

Range("BB.Org1").ListObject.AutoFilter.ApplyFilter

Range("BB.Org2").ListObject.AutoFilter.ApplyFilter

Range("BB.Org3").ListObject.AutoFilter.ApplyFilter

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,077
Messages
6,122,991
Members
449,094
Latest member
masterms

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