+ Reply to Thread
Results 1 to 2 of 2

Multiple Criteria

Hybrid View

efernandes67 Multiple Criteria 12-07-2011, 12:25 PM
efernandes67 Re: Multiple Criteria 12-08-2011, 07:14 AM
  1. #1
    Registered User
    Join Date
    01-01-2005
    MS-Off Ver
    2007
    Posts
    368

    Multiple Criteria

    Hi,

    I have this formula in a cell and I need someting that returns the same result in VBA.

    ={MATCH(1;(Name="John")*(Type="x")*(sDate>=DATEVALUE("01-01-2011"))*(eDate<=DATEVALUE("31-12-2011"));0)}

    I tried the code below, but it does not work:

    Sub MultipleCriteria()
        Dim rec As Variant
        Dim myName, myType As String
        Dim sDt, eDt As String
        
        myName = "John"
        myType = "x"
        sDt = "01-01-2011"
        eDt = "31-12-2011"
           
        With Application.WorksheetFunction
            rec = .Match(1, (Range("Name") = myName) * (Range("Type") = myType) * (Range("sDate") >= DateValue(sDt)) * (Range("eDate") <= DateValue(eDt)), 0)
        End With
    End Sub
    Regards,
    Elio Fernandes
    Last edited by efernandes67; 12-08-2011 at 07:15 AM.

  2. #2
    Registered User
    Join Date
    01-01-2005
    MS-Off Ver
    2007
    Posts
    368

    Re: Multiple Criteria

    Hi,

    I solved the problem using EVALUATE formula.

    Sub MultipleCriteria()
        Dim myName As String
        Dim sDt, eDt As Variant
        Dim rec As Variant
        
        myName = "John"
        myType = "x"
        sDt = Format("01-01-2011", "#")
        eDt = Format("31-12-2011", "#")
        rec = Evaluate("Match(1,(tbPlan[Name]=""" & myName & """)*(tbPlan[Type]=""" & myType & """)*(tbPlan[sDate]>=" & sDt & ")*(tbPlan[eDate]<=" & eDt & "),0)")
    End Sub
    Elio Fernandes

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1