VBA help

Donai

Well-known Member
Joined
Mar 28, 2009
Messages
543
Hi, i am after a macro that will filter for JPM and RBS when the user saves the file. At present staff members are leaving filters on for various headers, but i want to be sure when the workbook is saved the data is filtered for only those two banks.

Excel Workbook
ABCDEFGHIJKL
5NameGroupCategorySet IDValue DateEntry DateTypeAmountCCYAgeSourceRef1
6TESTTESTTESTTESTTESTTESTTESTTESTTESTJPMTEST
7JoeTESTTESTTESTTESTTESTTESTTESTTESTTESTCITITEST
8TESTTESTTESTTESTTESTTESTTESTTESTTESTJPMTEST
9TESTTESTTESTTESTTESTTESTTESTTESTTESTRBSTEST
10TESTTESTTESTTESTTESTTESTTESTTESTTESTBONYTEST
11TESTTESTTESTTESTTESTTESTTESTTESTTESTJPMTEST
Sheet1
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Just record a macro applying the filter you want, then call it from the BeforeSave/BeforeClose events. Although I'd probably do it from the Open event instead.

HTH,
 
Upvote 0
Put this in the ThisWorkbook module.

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Application.ScreenUpdating = False
    With Sheets("Sheet1")
        .AutoFilterMode = False
        .Range("A5:L" & Rows.Count).AutoFilter Field:=11, Criteria1:="JPM", Operator:=xlOr, Criteria2:="RBS"
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,270
Members
452,902
Latest member
Knuddeluff

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