Dynamic Filter Range

jakeman

Active Member
Joined
Apr 29, 2008
Messages
325
Office Version
  1. 365
Platform
  1. Windows
I'd like to create a dynamic filter range, preferably without using a named range. That said, here is the VBA code that I have for the filter I created using the Macro Recorder:

Code:
    ActiveSheet.Range("$A$1:$DE$139").AutoFilter Field:=1, Criteria1:= _
        xlFilterLastMonth, Operator:=xlFilterDynamic

Now, where I would need the dynamic range is for the column and row number, which change frequently. Sometimes the data goes to Column DE and sometimes DF or DG, etc. Also, each month I append new data so the rows are always increasing.

I created some code to count the number of columns and rows:

Code:
    Dim RangeFind, RangeFind2 as Integer

    RangeFind = Range("A1").End(xlToRight).Column
    RangeFind2 = Range("A1").End(xlDown).Row

Can I use those variables in the range for the filter?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
In your code replace A1 & DE139 with the "cells" version to reference the cell ie cells(1,1) and cells(rangefind2,rangefind)

like this

ActiveSheet.Range(cells(1,1),Cells(Rangefind2,Rangefind)).AutoFilter Field:=1, Criteria1:= _
xlFilterLastMonth, Operator:=xlFilterDynamic

<colgroup><col></colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,203,556
Messages
6,056,073
Members
444,842
Latest member
DeeMan

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