+ Reply to Thread
Results 1 to 6 of 6

Evaluate formula

Hybrid View

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

    Evaluate formula

    Hi,

    I have a table named 'table1' with 2 columns, 'Name' and 'sdate'

    sub test_Evaluate()
        Dim rec1, rec2 as variant
        Dim myName as String
        Dim sDt as date
        
        ' This WORKS
        myName="John"
        rec1 = Sheet1.Evaluate("Match(""" & myName & """,table1[Name],0)")
    
        ' It DOES NOT WORK
        sDt="07-12-2011"
        rec2 = Sheet1.Evaluate("Match(""" & sDt & """,table1[sDate],0)")
    
    End Sub
    What do I need to change in the 2nd Evaluate formula to make it work?

    Regards,
    Elio Fernandes
    Last edited by efernandes67; 12-08-2011 at 07:00 AM.

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,794

    Re: Evaluate formula

    Have you tried to dim sDt as String?

    Alf

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

    Re: Evaluate formula

    I tried with String, Date and Variant!

    Elio Fernandes

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Evaluate formula

    hi Elio, A16:E16 have word "test" in on of the cells

    Sub tet()
    x = "test"
    y = Evaluate("match(" & """" & x & """" & ",a16:e16,0)")
    End Sub

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

    Re: Evaluate formula

    Hi,

    I just found a way to work with this date issue.

    Sub test_Evaluate2()
        Dim rec1, rec2 As Variant
        Dim myName As String
        Dim sDt As Variant
        
        '.....
    
        ' IT IS WORKING NOW
        sDt = Format("11-12-2011", "#")
        rec2 = Sheet1.Evaluate("Match(" & sDt & ",table1[sDate],0)")
    End Sub
    Thanks for your help.
    Elio Fernandes
    Last edited by efernandes67; 12-08-2011 at 06:52 AM.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Evaluate formula

    sDt="07-12-2011"
        rec2 = Sheet1.Evaluate("Match(""" & sDt & """,table1.columns(2),0)")
    or
    [c12]=format("07-12-2011","yyyy-mm-dd")
    rec2=[match(c12,index(table1,,2),0)]
    Last edited by snb; 12-08-2011 at 06:39 AM.



+ 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