|
|
 |
| 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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

April 16th, 2008, 01:00 AM
|
|
Registered User
|
|
Join Date: Apr 2008
Location: , , Hong Kong.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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...
|

April 16th, 2008, 03:40 AM
|
|
Friend of Wrox
|
|
Join Date: Sep 2005
Location: , , .
Posts: 420
Thanks: 0
Thanked 14 Times in 14 Posts
|
|
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)
|

April 16th, 2008, 04:35 AM
|
|
Registered User
|
|
Join Date: Apr 2008
Location: , , Hong Kong.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |