Solved

Autorun autofilter upon opening a worksheet

Posted on 2014-01-06
10
340 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
  • 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now