On workbook close undo advanced filter

Xx7

Board Regular
Joined
Jan 29, 2011
Messages
126
I have filtered data in Sheet1. When I close the workbook I would like a macro to automatically unfilter the data. Therefore, when I open it next time, all the data is unfiltered on Sheet1. This only has to occur on Sheet1. I would prefer that no adjustments be made to the other sheets.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
I sometimes do something similar, but the way I do it is to use an auto execute macro which runs whenever I OPEN the file, to remove any filtering that may be in place.

Is that an option for you ? If yes, I'll post some code.
 
Upvote 0
Two variants of code, the first one is that Gerald has mentioned:
Rich (BB code):

' Put code into ThisWorkbook module

' Unhide rows hidden by filter (at opening of workbook)
' (Suggestion of Gerald Higgins)
Private Sub Workbook_Open()
  With Sheets("Sheet1")
    If .FilterMode Then .ShowAllData
  End If
End Sub

' Unhide rows hidden by filter (at saving of workbook)
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
  With Sheets("Sheet1")
    If .FilterMode Then .ShowAllData
  End If
End Sub
 
Upvote 0
Please replace End If by End With in the code above.
The fixed code:
Rich (BB code):

' Put code into Thisworkbook module

' Unhide rows hidden by (advanced) filter at opening of workbook
' (Suggestion of Gerald Higgins)
Private Sub Workbook_Open()
  With Sheets("Sheet1")
    If .FilterMode Then .ShowAllData
  End With
End Sub

' Unhide rows hidden by (advanced) filter at saving of workbook
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
  With Sheets("Sheet1")
    If .FilterMode Then .ShowAllData
  End With
End Sub
 
Upvote 0
I sometimes do something similar, but the way I do it is to use an auto execute macro which runs whenever I OPEN the file, to remove any filtering that may be in place.

Is that an option for you ? If yes, I'll post some code.

That could work. I'm running a macro to insert hyperlinks into the worksheet on open too. However I need to unfilter the sheet first or else my hyperlinks don't update correctly. I'm assuming I can do both of these on open?? Just unfilter them first... or will these conflict?
 
Upvote 0
ZVI,

I'm getting a "run-time error '9': Subscript out of range", when I run your revised code. Any advice?
 
Upvote 0
ZVI,

I'm getting a "run-time error '9': Subscript out of range", when I run your revised code. Any advice?
It was assumed that Sheets("Sheet1") is present, if the sheet name is different then replace "Sheet1" in the code by the actual sheet name
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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