Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Autorun autofilter upon opening a worksheet

Posted on 2014-01-06
10
Medium Priority
?
478 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 31

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 31

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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

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 31

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 31

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 31

Accepted Solution

by:
gowflow earned 2000 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 31

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

636 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