AutoFilter for current table instead of manually defining cells

PatRichard

New Member
Joined
Dec 29, 2018
Messages
29
Office Version
  1. 365
Platform
  1. Windows
I have a macro based on a page here

Sub Gen1()
Range("A4").Select
Selection.CurrentRegion.Select
Selection.AutoFilter
ActiveSheet.Range("$A$3:$AF$117").AutoFilter Field:=3, Criteria1:="1"
End Sub

It works great. However, my table of data is constantly growing. I'm struggling to find a way to automatically apply the filter to the current table instead of editing the macro each time to include the range. Can someone point me in the right direction?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I think you should use A Table Name

Select the current range with your data and choose Insert Table from the Insert Menu on the Ribbon

As the range of the table expands the script takes this into consideration.

Use this script:

Code:
Sub My_Sub()
'Modified  12/29/2018  2:54:08 AM  EST
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=3, Criteria1:="1"
End Sub
 
Upvote 0
Awesome. I already had made it a table, so using your code was all I needed. Appreciate the info.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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