Consulting

Results 1 to 4 of 4

Thread: worksheet function match syntax issue

  1. #1
    VBAX Newbie
    Joined
    May 2012
    Posts
    5
    Location

    worksheet function match syntax issue

    I am writing a vba script that will look up the row of a time function. I have a named range Date_Time that refers to a range in worksheet "Schedule" of A:A. Here is what I have :

    Dim vlline as long

    vlline = Application.Worksheetfunction.Match(stDate,Range(Date_Time))

    Note stDate is defined in a cell with data validation of the range Date_Time.

    I get an error 1004

    I have tried to change the match function also to (stDate,Worksheets("Schedule").Range("A:A")) and that does not work either.

    What am I missing?

  2. #2
    VBAX Regular
    Joined
    Feb 2013
    Posts
    52
    Location
    On my system Application.Worksheetfunction.Match never works. I have to omit the Worksheetfunction word and use just Application.Match which works even tho when doing this Match doesn't appear in the list of functions that pops up after typing in Application. Have no idea why, but works for me.

  3. #3
    VBAX Contributor GarysStudent's Avatar
    Joined
    Aug 2012
    Location
    Lakehurst, NJ, USA
    Posts
    127
    Location
    Give MATCH() a Range as the first argument:

    Sub durl()
        Dim d As Range
        Dim Date_Time As Range
        Dim N As Long
        Set Date_Time = Range("B2:B16")
        Set d = Range("B6")
        N = Application.WorksheetFunction.Match(d, Date_Time, 0)
        MsgBox N
    End Sub
    Have a Great Day!

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    • If match_type is 1, MATCH finds the largest value that is less than or equal to lookup_value. Lookup_array must be placed in ascending order: ...-2, -1, 0, 1, 2, ..., A-Z, FALSE, TRUE.
    • If match_type is 0, MATCH finds the first value that is exactly equal to lookup_value. Lookup_array can be in any order.
    • If match_type is -1, MATCH finds the smallest value that is greater than or equal to lookup_value. Lookup_array must be placed in descending order: TRUE, FALSE, Z-A, ...2, 1, 0, -1, -2, ..., and so on.
    • If match_type is omitted, it is assumed to be 1.
    On Error Resume Next
    vlline = Range(Date_Time).Find(stDate).Row
    If Range(Date_Time).Find(stDate) Is Nothing Then MsgBox "Date Not Found"
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Tags for this Thread

Posting Permissions

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