VBA code - filter reset on closure

Rebro88

New Member
Joined
May 30, 2018
Messages
7
Hello

After numerous google searches and failed attempts. I'm giving in and asking for advice as my VBA knowledge is very little.

I have a workbook that has protected cells where my colleagues report actions. The filters are turned on so they can filter the actions based on department, shift etc.

Is there a VBA code that will reset any filters applied and not remove them?

The codes I have tried through my google searches remove the filters which then requires the sheet to be unlocked and the filter added again.

Thanks in advance
Rebro88
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Do you mean this?

VBA Code:
ActiveSheet.ShowAllData
 
Upvote 0
still think with the above, you will need to unprotect the workbook.

but this can be coded too
 
Upvote 0
Something like the below example

on workbook close

VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets("Sheet1").Unprotect "Password"
ActiveSheet.ShowAllData
Worksheets("Sheet1").protect "Password"
End Sub
 
Upvote 0
Something like the below example

on workbook close

VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets("Sheet1").Unprotect "Password"
ActiveSheet.ShowAllData
Worksheets("Sheet1").protect "Password"
End Sub

Thanks for the quick replies.

This is the closest its has been to working.

The only issue is when it unprotects and protects it takes away the protect sheet option autofilter and format rows.

Is there a way around this?
 
Upvote 0
Hi, sorry for the late reply

play with the true and false in the below. until you get your desired results

however, im suprised you didnt flag me an about a possible save notification on close.

see how you get on

VBA Code:
Sub db()
strPword = "password"
Worksheets("Sheet1").Unprotect strPword
ActiveSheet.ShowAllData
Worksheets("Sheet1").Protect Password:=strPword, DrawingObjects:=True, Contents:=True, Scenarios:=True, _
UserInterfaceOnly:=True, AllowFormattingCells:=False, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=False, AllowInsertingRows:=False, _
AllowInsertingHyperlinks:=False, AllowDeletingColumns:=False, AllowDeletingRows:=False, _
AllowSorting:=False, AllowFiltering:=True, AllowUsingPivotTables:=False
End Sub
 
Upvote 0
Is there a way around this?
As @SQUIDD notes in his post, the Worksheets("Sheet1").Protect command has a lot of options/properties available to you, so you can configure the sheet protection as you like.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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