I want excel to unfilter cells before user saves

andresmcc

New Member
Joined
Jun 18, 2002
Messages
23
I have a spreadsheet that is updated by several users. Some times people save chnges to it and forget to unfilter or unhide cells. This is anoying to other users. Is there a function, macros, or VBA Code that can unfilter and unhide before saving, or at least remind the user to do so before saving his changes?

Thanks
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Gracias Juan Pablo

I wasn't very clear though. I want Excel to do this everytime a user clicks on "Save". That is the part I don't know how to do. How would I program Excel to perform this on each save?
 
Upvote 0
Try this.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim c As Integer
Dim f As Filter
Dim w As Worksheet
Set w = Worksheets("YOUR SHEET NAME")
Worksheets("YOUR SHEET NAME").Activate
c = 0
Application.ScreenUpdating = False
For Each f In w.AutoFilter.Filters
c = c + 1
Selection.AutoFilter Field:=c
Next

End Sub
 
Upvote 0
Hi Andress,

Here is some code that you can put in the ThisWorkbook event module to expand all the filters on the active worksheet before saving. If you want to target a specific worksheet other than the active worksheet just replace ActiveSheet with Worksheets("Your worksheet name") in the code below.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'Expand (turn off) all filters on the active worksheet
Dim Fltr As Filter
Dim iFiltr As Integer
With ActiveSheet.AutoFilter
For iFiltr = 1 To .Filters.Count
If .Filters(iFiltr).On Then
.Range.AutoFilter field:=iFiltr
End If
Next iFiltr
End With
End Sub

To install this code simply right-click on the Excel icon at the left end of the Excel Worksheet Menu Bar, select View Code, and paste the above code into the VBE code pane.
 
Upvote 0

Forum statistics

Threads
1,203,044
Messages
6,053,185
Members
444,643
Latest member
Shipwreck818

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