Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 16th, 2008, 12:00 AM
Registered User
 
Join Date: Apr 2008
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...



 
Old April 16th, 2008, 02:40 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 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)
 
Old April 16th, 2008, 03:35 AM
Registered User
 
Join Date: Apr 2008
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!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Enter Key Event (Enter Key Only) Coby Excel VBA 0 February 6th, 2008 09: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 05:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.