Solved

Autorun autofilter upon opening a worksheet

Posted on 2014-01-06
10
415 Views
Last Modified: 2014-01-08
Hi,  (I might have figured this out a long time ago, albeit slowly, but I was never very good at VBA) :(


I have the same advanced filter on a few worksheets (in same workbook) and I need the auto-filter to immediately auto-run when the worksheet is opened.  That is, when a  worksheet that has an advanced filter set in it.

Can you help please.  

BTW: If you want a copy of the workbook please yell & I'll have to dummy one up for you (as it's confidential data).
0
Comment
Question by:kazmdav
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 29

Expert Comment

by:gowflow
ID: 39761530
could you post the workbook so we make sure it is done correctly.
But offhand whatever code to prepare for autofilter if you want it to be activated when you open the workbook then you should make sure the code is in this Sub

Private Sub Workbook_Open()

End Sub

Open in new window


gowlfow
0
 

Author Comment

by:kazmdav
ID: 39763778
Sure, no worries! A dummied up sample workbook is attached.  Example use:  In 'Foundation Skills (1)' in Col A, user selects from drop down. Foundation Skills (2) has the advanced filter (ie; filter out the rows that had 'No' selected). It's this filter that I want to occur when this worksheet is opened.

Same concept for Specialisation (1) & Specialisation (2) worksheets.  Thus when Specialistation (2) is opened I want the advanced filter to occur too.


Hope this helps!
Sample-workbook.xls
0
 
LVL 29

Expert Comment

by:gowflow
ID: 39764530
ok lets take it step by step.

First I see some errors in sheet Foundation Skills (2) Row 3, 4, 5, 6 is it safe to delete these rows or something else should go there ?? as they point to Foundation Skills (1) #REF! ref means that the reference to the mentioned sheet is missing.

gowflow
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:kazmdav
ID: 39764557
Yes no problems, safe to delete them (it's as a result of me removing heaps of confidential data from Foundation skills (1)).

cheers!
0
 
LVL 29

Expert Comment

by:gowflow
ID: 39764566
Furthermore I noticed that maybe in your sample workbook you made a crucial mistake of design where you included the choices in the sheets (2) like if the user go on sheet 2 and select a No then it will disappear from that sheet and will still show no value in the initial sheet 1

I think your aim is to have the user select in sheet 1 and have the sheets 2 for lookup and have it filtered excluding No Am I right ???
gowflow
0
 
LVL 29

Expert Comment

by:gowflow
ID: 39764572
Also what about the option of No but interested ? you want to be filtered out or kept showing ??
gowflow
0
 
LVL 29

Accepted Solution

by:
gowflow earned 500 total points
ID: 39764649
ok here it is

Having not answered my previous question,

I have assumed that you input in sheets labeled 1 and have sheets labeled 2 to filter data excluding the No items (it will still show the No but interested items. I have removed the Validation from sheets (2) to prevent any input in these sheets accidentally that will not be reflected in Sheets (1)

Your problem actually is not only in the Open of the workbook but actually all the time the workbook is in the works. As you posted an .xls version the behavior in Excel 2003 is that the filter need to be activated so see the items filtered.

The version I am posting will thru macro activate the filtering in all time from open to close based on showing all items except the ones that are strictly No. If you need to change this behavior then, the code will need to be changed.

I have put the same code in both events. I will post the code for your convenience. You will need to put the same code in your production workbook.

Workbook_SheetChange
Workbook_Open

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim WSFound2 As Worksheet
Dim WSSpeci2 As Worksheet

Set WSFound2 = Sheets("Foundation Skills (2)")
Set WSSpeci2 = Sheets("Specialisation (2)")

WSFound2.Range("A:A").AutoFilter Field:=1, Criteria1:="<>" & "No"
WSSpeci2.Range("A:A").AutoFilter Field:=1, Criteria1:="<>" & "No"
End Sub

Open in new window


Private Sub Workbook_Open()
Dim WSFound2 As Worksheet
Dim WSSpeci2 As Worksheet

Set WSFound2 = Sheets("Foundation Skills (2)")
Set WSSpeci2 = Sheets("Specialisation (2)")

WSFound2.Range("A:A").AutoFilter Field:=1, Criteria1:="<>" & "No"
WSSpeci2.Range("A:A").AutoFilter Field:=1, Criteria1:="<>" & "No"
End Sub

Open in new window


Pls check out the file and let me know your comments.
gowflow
Sample-workbook.xls
0
 

Author Comment

by:kazmdav
ID: 39764725
Perfect! Thank you gowflow. Exactly what I wanted & I don't believe I require anything further.

I will put the code into production workbook tomorrow.  After the update & successful test in prod, I will return here to close the question.  

Sorry for no response; was on way home from work.

Cheers!
0
 
LVL 29

Expert Comment

by:gowflow
ID: 39764814
No problem take your time and pls feel free to post here any link to any question you may need help with.
Rgds/gowflow
0
 

Author Closing Comment

by:kazmdav
ID: 39767093
All good. Thank you. :)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question