Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-11-2018, 07:19 AM
LearnerExcel LearnerExcel is offline How to modify code for Auto filter based on two criteria ... Windows 7 32bit How to modify code for Auto filter based on two criteria ... Office 2003
Advanced Beginner
How to modify code for Auto filter based on two criteria ...
 
Join Date: Nov 2016
Posts: 81
LearnerExcel will become famous soon enoughLearnerExcel will become famous soon enough
Default How to modify code for Auto filter based on two criteria ...


How to modify the following code for Auto filter to search based on two criteria ...
Like : CriteriaRange:=Range("E1:E2") & CriteriaRange:=Range("F1:F2")
Code:
 
PrivateSubWorksheet_Change(ByValTarget AsRange)
'Updateby Extendoffice 20160606
   IfTarget.Address = Range("E2").Address Then
       Range("A1:C20").CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("E1:E2")
   EndIf
EndSub
Source: https://www.extendoffice.com/documen...ell-value.html
Reply With Quote
  #2  
Old 02-11-2018, 12:52 PM
NoSparks NoSparks is offline How to modify code for Auto filter based on two criteria ... Windows 7 64bit How to modify code for Auto filter based on two criteria ... Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

What are the contents of E1:E2 and F1:F2 ?
Reply With Quote
  #3  
Old 02-11-2018, 01:54 PM
LearnerExcel LearnerExcel is offline How to modify code for Auto filter based on two criteria ... Windows 7 32bit How to modify code for Auto filter based on two criteria ... Office 2003
Advanced Beginner
How to modify code for Auto filter based on two criteria ...
 
Join Date: Nov 2016
Posts: 81
LearnerExcel will become famous soon enoughLearnerExcel will become famous soon enough
Default

E1=CustomerID
E2=Cust-001 ..... and so on

F1=Tax%
F2=2.50 or 5.00 or 9 or 18 and so on
Reply With Quote
  #4  
Old 02-11-2018, 02:41 PM
jeffreybrown jeffreybrown is offline How to modify code for Auto filter based on two criteria ... Windows Vista How to modify code for Auto filter based on two criteria ... Office 2007
Expert
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Maybe try...

From:
Code:
CriteriaRange:=Range("E1:E2")
To:
Code:
CriteriaRange:=Range("E1:F2")
Reply With Quote
  #5  
Old 02-11-2018, 08:39 PM
LearnerExcel LearnerExcel is offline How to modify code for Auto filter based on two criteria ... Windows 7 32bit How to modify code for Auto filter based on two criteria ... Office 2003
Advanced Beginner
How to modify code for Auto filter based on two criteria ...
 
Join Date: Nov 2016
Posts: 81
LearnerExcel will become famous soon enoughLearnerExcel will become famous soon enough
Default

Not working.
Reply With Quote
  #6  
Old 02-11-2018, 09:06 PM
jeffreybrown jeffreybrown is offline How to modify code for Auto filter based on two criteria ... Windows Vista How to modify code for Auto filter based on two criteria ... Office 2007
Expert
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Not working tells me nothing.

How about attaching a small sample workbook with your setup and how it doesn't work so we can maybe get it to work.
Reply With Quote
  #7  
Old 02-12-2018, 01:21 AM
LearnerExcel LearnerExcel is offline How to modify code for Auto filter based on two criteria ... Windows 7 32bit How to modify code for Auto filter based on two criteria ... Office 2003
Advanced Beginner
How to modify code for Auto filter based on two criteria ...
 
Join Date: Nov 2016
Posts: 81
LearnerExcel will become famous soon enoughLearnerExcel will become famous soon enough
Default

Working fine now. But how can I modify formula to search with field "Code" & "Tax%" instead of "Region" & "Tax%"? The problem here is, if the field Code has 1 Character or 5 Characters it should consider it as one criteria and if it has 8 characters then it should consider it as second criteria and accordingly filter the data.

It means, if I select "1" or "5" in E3 it should show all the rows related to 1 and 5 characters in field Code. If I enter "8" in E3 then it should show rows only related to 8 characters in field Code.
Reply With Quote
  #8  
Old 02-12-2018, 01:22 AM
LearnerExcel LearnerExcel is offline How to modify code for Auto filter based on two criteria ... Windows 7 32bit How to modify code for Auto filter based on two criteria ... Office 2003
Advanced Beginner
How to modify code for Auto filter based on two criteria ...
 
Join Date: Nov 2016
Posts: 81
LearnerExcel will become famous soon enoughLearnerExcel will become famous soon enough
Default

Sample file attached.
Attached Files
File Type: xlsm AutoFilter.xlsm (18.9 KB, 11 views)
Reply With Quote
  #9  
Old 02-12-2018, 03:37 PM
jeffreybrown jeffreybrown is offline How to modify code for Auto filter based on two criteria ... Windows Vista How to modify code for Auto filter based on two criteria ... Office 2007
Expert
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

IMHO, not sure why you even need to mess with advanced filter when you can just use the built in filter. Place the filter on row 5 and then on column B, filter for begins with.
Reply With Quote
  #10  
Old 02-13-2018, 08:31 PM
LearnerExcel LearnerExcel is offline How to modify code for Auto filter based on two criteria ... Windows 7 32bit How to modify code for Auto filter based on two criteria ... Office 2013
Advanced Beginner
How to modify code for Auto filter based on two criteria ...
 
Join Date: Nov 2016
Posts: 81
LearnerExcel will become famous soon enoughLearnerExcel will become famous soon enough
Default

Okay. Thanks.
Reply With Quote
  #11  
Old 02-14-2018, 07:34 AM
LearnerExcel LearnerExcel is offline How to modify code for Auto filter based on two criteria ... Windows 7 32bit How to modify code for Auto filter based on two criteria ... Office 2013
Advanced Beginner
How to modify code for Auto filter based on two criteria ...
 
Join Date: Nov 2016
Posts: 81
LearnerExcel will become famous soon enoughLearnerExcel will become famous soon enough
Default Is there any way to modify the folloiwng code so that it will hide the empty cells ..

Is there any way to modify the folloiwng code so that it will hide the empty cells with formula (as the following code does) and in additon to that it should filter data based on Cell G5 value?

Code:
 
Sub HideRowsMissingData()
Dim cl As Range, i As Integer
        
Application.ScreenUpdating = False
With Sheets("Sheet1")
    For Each cl In .Range("A4:A502")
        If cl.Value = "" Then
            .Rows(cl.Row).Hidden = True
        Else
            For i = 1 To 4
                If cl.Offset(, i).Value = "" Then
                    .Rows(cl.Row).Hidden = True
                    Exit For
                End If
            Next i
        End If
    Next cl
End With
Application.ScreenUpdating = True
End Sub
Reply With Quote
  #12  
Old 02-14-2018, 04:09 PM
jeffreybrown jeffreybrown is offline How to modify code for Auto filter based on two criteria ... Windows Vista How to modify code for Auto filter based on two criteria ... Office 2007
Expert
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Sorry, but I can't modify this macro without something to work from, that is a sample worksheet. I would be guessing as to your layout and I don't want to guess. The sheet you attached in post # 8 does not have anything in column A and cell G5 says Tax%.

If this query is not related to your original post, please post a separate question.
Reply With Quote
  #13  
Old 02-14-2018, 04:24 PM
macropod's Avatar
macropod macropod is offline How to modify code for Auto filter based on two criteria ... Windows 7 64bit How to modify code for Auto filter based on two criteria ... Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by jeffreybrown View Post
If this query is not related to your original post, please post a separate question.
The OP does say:
Quote:
Originally Posted by LearnerExcel View Post
in additon to that it should filter data based on Cell G5 value
which would seem to make the additional requirements related to the original post.

LearnerExcel: When posting questions, please supply the full details of the requirements. Revealing them piecemeal leads to frustration, particularly when code has to be re-written to accommodate previously-unspecified requirements.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #14  
Old 02-14-2018, 08:20 PM
LearnerExcel LearnerExcel is offline How to modify code for Auto filter based on two criteria ... Windows 7 32bit How to modify code for Auto filter based on two criteria ... Office 2013
Advanced Beginner
How to modify code for Auto filter based on two criteria ...
 
Join Date: Nov 2016
Posts: 81
LearnerExcel will become famous soon enoughLearnerExcel will become famous soon enough
Default

Sorry, by mistake I posted here instead of NEW query. I will post a new one with sample data. This post is closed.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to modify code for Auto filter based on two criteria ... Sum based on multiple criteria (one of the criteria is not unique) until a threshold is reached. phillipsdp Excel 1 11-09-2016 12:53 AM
How to modify code for Auto filter based on two criteria ... Filter Mail Merge based on a list of filter criteria AusSteelMan Mail Merge 2 05-09-2016 03:35 PM
Auto fill drops down using VBA code based on selection AgilityJS Word VBA 5 11-03-2015 07:50 PM
Forgotten Sort and Filter Criteria rbdmg Mail Merge 0 10-31-2011 09:14 PM
Modify vba code to print based on name in the InputBox OTPM Project 0 05-25-2011 02:03 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:21 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft