Macro (using a Filter) Question and help

oldmaninla

New Member
Joined
Oct 7, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
I have the following macro.
Originally, the Filter Button in Excel was in column AA but I couldn't make it work so I moved the Filter to Column A (1).
If I only want to have the filter button in Column AA how can I make my macro work?
I tried changing the AutoFilter Field:=27 but that doesn't work.
Any ideas? Thx



Sub ShowOnly_1()
'
' ShowOnly_1 Macro
'

'
Dim ws As Worksheet

For Each ws In Worksheets

'Range("AA5").Select
'ActiveSheet.Range("$AA$5:$AA$618").AutoFilter Field:=1, Criteria1:="show"
If ws.Visible = True Then
If ws.Name <> "Input" then
If ws.Name <> "Control" then
ws.Activate
ActiveSheet.Range("$A$5:$A$618").AutoFilter Field:=1, Criteria1:="show"

End If
End If
End If
Next

End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
If you want to set only AA as the filter then use AA but it's field 1, as in the first column in the range

VBA Code:
Option Explicit

Sub ShowOnly_1()
Dim ws As Worksheet                                                                 ' Variable to store the worksheet


For Each ws In ThisWorkbook.Worksheets                                              ' Loop over all the worksheets
    
    With ws                                                                         ' use With to save repeating the variable
        
        If .Visible = True Then                                                     ' test if the sheet is visible
            
            If InStrRev("|Input|Control|", "|" & .Name & "|") = 0 Then              ' Test the name is one we want to use
                
                .Activate                                                           ' activate the sheet - this is unnecessary
                
                .Range("$AA$5:$AA$618").AutoFilter Field:=1, Criteria1:="show"      ' Filter on column AA if the value is Show
            
            End If                                                                  ' End the test for sheet name
        
        End If                                                                      ' end the visibility test
    
    End With                                                                        ' end the use of the sheet

Next ws                                                                             ' move to the next sheet

End Sub
 
Upvote 0
Solution
Thx Dave3009, but for some reason, it still wants to Filter on Column 1
 
Upvote 0
OK, I did not ask about cell AA5, I asked about row 5. Are there any formulas in row 5, especially cell A5?
 
Upvote 0
Hi Dave3009- I moved the one formula in row 5, cleared the Filter that was still on A5 and now it is working fine. Thank you for your direction!
 
Upvote 0

Forum statistics

Threads
1,223,935
Messages
6,175,494
Members
452,649
Latest member
mr_bhavesh

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