• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA - advanced filter help...

Malleshg24

New Member
Hi Team,

I am using below code and its giving Correct result.

Situation1
Column A, B, C, are my Raw data,
Situation1, Column F,G,H Are my filter Criteria List.{Filter In}

Situation2, Same situation but exclude Column J Criteria list (Filter Out)
Situation2 - Column J,K,L Are my filter Criteria List.


How to achieve same result via advanced filter in both Situation.
Criteria list my Increase.

if possible can you Suggest a dynamic function to cover Multiple Situations Like this. (10-15 Situation)

Code:
Option Explicit
Sub Count_as_Per_Criteria()

Dim ar1 As Variant
Dim ar2 As Variant
Dim ar3 As Variant

ar1 = Sheet1.Range("F3", Range("F" & Rows.Count).End(xlUp))
ar2 = Sheet1.Range("G3", Range("G" & Rows.Count).End(xlUp))
ar3 = Sheet1.Range("H3", Range("H" & Rows.Count).End(xlUp))

 Dim i As Long, Situation1 As Long, lr As Long
 lr = Sheet1.Range("A" & Rows.Count).End(xlUp).Row
 
 'Situaction 1 Include all Criteria  ' Code is working
 For i = 2 To lr
    If IsNumeric(Application.Match(Sheet1.Cells(i, 1).Value, ar1, 0)) Then
         If IsNumeric(Application.Match(Sheet1.Cells(i, 2).Value, ar2, 0)) Then
            If IsNumeric(Application.Match(Sheet1.Cells(i, 3).Value, ar3, 0)) Then
                    Sheet1.Cells(i, 1).Resize(1, 3).Font.Color = vbBlue
                Situation1 = Situation1 + 1
            End If
        End If
    End If
Next i

MsgBox Situation1


'----------Situation2 Count--------------------

ar1 = Sheet1.Range("J3", Range("J" & Rows.Count).End(xlUp))
ar2 = Sheet1.Range("K3", Range("K" & Rows.Count).End(xlUp))
ar3 = Sheet1.Range("L3", Range("L" & Rows.Count).End(xlUp))

Dim Situation2 As Long

For i = 2 To lr
    If IsNumeric(Application.Match(Sheet1.Cells(i, 1).Value, ar1, 0)) = False Then 'Something wrong here, How to exclude.
         If IsNumeric(Application.Match(Sheet1.Cells(i, 2).Value, ar2, 0)) Then
            If IsNumeric(Application.Match(Sheet1.Cells(i, 3).Value, ar3, 0)) Then
                    Sheet1.Cells(i, 1).Resize(1, 3).Font.Color = vbRed
                Situation2 = Situation2 + 1
            End If
        End If
    End If
Next i

MsgBox Situation2


End Sub
Thanks
mg
 
Hi Mark L,

Thanks for your help, to some extent I know advanced filter how it works,
But Unable to fix it in my situation. Can you suggest how to apply in my situation ,

Most of the time I come across this situation.


Thanks
mg
 
Malleshg24
You've written ...
I am using below code and its giving Correct result.
How to achieve same result via advanced filter in both Situation.

Q: How someone else than You would know Your 'correct results' and compare those to something else?
 
Back
Top