unfilter

G

Guest

hi,
In VBA, how can I restore filter before saving.for example, in sheet1 the
rows10 to 20 are invisible(filtered), I need a code by which
unfilter the worksheet ( all the worksheets,if they are in filter mode) with
no invisible rows and then save the workbook?
thanks
 
B

Bob Umlas

Range("A9").autofilter
(assumes A9 is one of the title rows of the data which is filtered.
 
M

mk

hi,
In VBA, how can I restore filter before saving.for example, in sheet1 the
rows10 to 20 are invisible(filtered), I need a code by which
unfilter the worksheet ( all the worksheets,if they are in filter mode) with
no invisible rows and then save the workbook?
thanks

hey peyman,

you need to go to Visual Basic window, double click on ThisWorkbook
object of your excel file and insert the following code:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
For i = 1 To Sheets.Count
Worksheets(i).Select
If Worksheets(i).AutoFilterMode = True Then
Cells.Select
Selection.AutoFilter
Cells(1, 1).Select
End If
Next i
End Sub

Before saving, this code will check every sheet for filters and remove
them.

Best,
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top