Need Help Creating a Macro that will unfilter the entire sheet, and then create a filter in a specific row (different on each sheet)

dnorber

New Member
Joined
Mar 19, 2009
Messages
38
So I work with a lot of spreadsheets where there are filters, however, the filter is on a different row in each spreadsheet. My feeling is that there is a macro I can create that will unfilter a sheet (easy enough right, select the entire sheet and then do data: filter: unclick autofilter). The trick is determining which row to create the new filter.

It seems to me, the best way to do this is to ensure that Column A is clear until the row I want to filter (that is, the first row Column A that has information entered in it is the one that I want to filter).

I just don't know the VBA command to look for the first cell that has an entry.

Can anyone help, or know how to create that Macro?

Thank you!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
welcome to MrExcel Board....

try this to find the first cell with data in column

Sub firstrow()
x = Range("A1").End(xlDown).Address(False, False)
MsgBox "First row with data " & x
End Sub
 
Upvote 0
Thanks for the welcome. I grabbed an answer off the board last week, and it was perfect, so I am hopeful that the experts here can help with my infrequent questions as well.

the macro you have suggested works perfectly to identify the 1st cell in Column A that has data. How can I convert the second part of this macro to, instead of returning a message box that tells me where the first set of data is, to highlighting the entire row, and then doing an auto-filter on that row?

Thanks!
 
Upvote 0
try this

Sub firstrow()
x = Range("A1").End(xlDown).Address(False, False)
Range(x).AutoFilter
End Sub
 
Upvote 0
YES!

Thank you so much!

Edit: ok, so that works, but I've messed up the the first part of the macro.
What I want to do is select all cells, undo the autofilter, and then create this new autofilter...here is what I am using

Sub firstrow()
Cells.Select
Selection.AutoFilter
x = Range("A1").End(xlDown).Address(False, False)
Range(x).AutoFilter
End Sub

but it doesn't work. It just ends up highlighting my worksheet
 
Last edited:
Upvote 0

Forum statistics

Threads
1,203,562
Messages
6,056,086
Members
444,845
Latest member
dpkane512

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