Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 16th, 2008, 12:00 AM
Registered User
 
Join Date: Apr 2008
Location: , , Hong Kong.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Enter Criteria Above Header To apply Autofilter

Hi all,

i need help with Worksheet_Change event!!!

Pl see code below:

Code:
Private Sub Worksheet_Change(ByVal Target As  Range) 

    ActiveSheet.AutoFilterMode = False 
    Range("d6:g6"). AutoFilter 
    Range("d6:g6").AutoFilter Field:=2, Criteria1:=Range("e1"), Operator:=xlAnd, _ 
    Criteria2:=Range("e2")
Cant see a facility to attach mu file.
But, will b happy to email the same if required.

What i intend to do is that : (1) if i enter a value in E3, the filter should only apply using E3 value (currently its applying E3 value but if E4 is kept blank, it takes that as = " " ) . Unfortunately, i need to have the and condition, so i have to find a way in spite of this condition. Any way out ??

(2) If i enter values in A) E3 & F3 B) E3, F3, G3...then it should make multiple filtering possible. But when i try to apply such a condition, the same problem as in point (1) occurs, it takes the and empty criteria range as = " "

Any help on this please ?
thx a lot in advance...



Reply With Quote
  #2 (permalink)  
Old April 16th, 2008, 02:40 AM
Friend of Wrox
Points: 2,950, Level: 22
Points: 2,950, Level: 22 Points: 2,950, Level: 22 Points: 2,950, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 788
Thanks: 1
Thanked 51 Times in 47 Posts
Default

Hi

Can you use a If condition like following:

Code:
    If Len(Trim(Range("e2"))) <> 0 Then
        Range("d6:g6").AutoFilter Field:=2, Criteria1:=Range("e1"), Operator:=xlAnd, _
        Criteria2:=Range("e2")
    Else
        Range("d6:g6").AutoFilter Field:=2, Criteria1:=Range("e1")
    End If
Cheers
Shasur

http://www.dotnetdud.blogspot.com

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Reply With Quote
  #3 (permalink)  
Old April 16th, 2008, 03:35 AM
Registered User
 
Join Date: Apr 2008
Location: , , Hong Kong.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

thx a lot, this one does work !!!!

only when i remove both E1 & E2, criteria, instead of doing filtermode FAlSE, it still treats it as "equals "blank".

but yes, the basic functionality is acheived!

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Enter Key Event (Enter Key Only) Coby Excel VBA 0 February 6th, 2008 08:55 PM
How to display filter criteria in report header?? Jabba007 Access 2 July 17th, 2007 12:06 PM
Remove Autofilter yogeshyl Excel VBA 4 June 11th, 2007 06:59 AM
AutoFilter 5 columns at once Pindacko Excel VBA 0 April 26th, 2006 05:33 AM
Autofilter taking too much of time raaghu15 Excel VBA 2 March 4th, 2005 04:43 PM



All times are GMT -4. The time now is 04:20 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.