Excel VBA Help, Filters

Chris_010101

Board Regular
Joined
Jul 24, 2017
Messages
187
Office Version
  1. 365
Platform
  1. Windows
Hello,

In column A, I have:
Excel Formula:
=SORT(UNIQUE(FILTER('Headcount Report'!A3:A909, 'Headcount Report'!A3:A909<>"")))
which pulls a list of unique values. In this list are locations by type, i.e St Albans - Yard, Colchester - Transport. The three types are "Office", "Yard" and "Transport" all appended with a hyphen a the end of the location.

In corresponding columns are headcount, vacancies and other information. I have created macro buttons to filter column A by the three types mentioned above. However, if I expand the list, say we add a new location, it doesn't come through in the filter. I have to re-record the macro, which is annoying.

Example:
VBA Code:
Sub Office()
'
' Office Macro
'

'
    ActiveSheet.Range("$A$1:$D$46").AutoFilter Field:=1, Criteria1:=Array( _
        "Belfast - Office", "Bristol - Office", "Chester - Office", "Colchester - Office", _
        "Newbury - Office", "Peterlee - Office", "Rochford - Office", "Sandtoft - Office", _
        "Sandwich - Office", "Sandy - Office", "Westbury - Office", "Whitburn - Office", _
        "Wisbech - Office", "Wolverhampton - Office", "York - Office"), Operator:= _
        xlFilterValues
    ActiveWindow.SmallScroll Down:=-6
End Sub

This doesn't update when the filtered list in column A is changed. For example, if I was now to add "St Albans - Office" to the array, the macro would not pick it up unless I re-record it.

Kind Regards
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
How about
VBA Code:
Sub Office()
'
' Office Macro
'

'
    ActiveSheet.Range("$A$1:$D$46").AutoFilter Field:=1, Criteria1:="*Office*"
    ActiveWindow.SmallScroll Down:=-6
End Sub
 
Upvote 1
Solution
You're welcome & thanks for the feedback.
 
Upvote 1

Forum statistics

Threads
1,215,039
Messages
6,122,799
Members
449,095
Latest member
m_smith_solihull

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