+ Reply to Thread
Results 1 to 4 of 4

Date in MATCH formula

  1. #1
    David
    Guest

    Date in MATCH formula

    Hi Group,
    I have some code to do a Match on a date, if the date is hard coded in the
    formula it works just fine, but i am trying to get that date in via a
    variable.

    This works:
    ActiveCell.FormulaR1C1 = "=MATCH(""1/25/99""+0,DateRange,-1)"
    but his does not:
    ActiveCell.FormulaR1C1 = "=MATCH(" & (Z1) & "+0,DateRange,-1)"
    Z1 is the variable with the same date, but it fails to get the " " around
    the date and fails.

    The +0 is not being used currently, but is will be used to find an
    appromiate date, later in the code, one year later. It is being used in a
    table with about 5 years worth of data.

    Thanks,

    --
    David

  2. #2
    Dave Peterson
    Guest

    Re: Date in MATCH formula

    Just like you doubled up those quotations in your example that worked...

    Dim Z1 As String
    Z1 = "1/25/99"
    ActiveCell.FormulaR1C1 = "=MATCH(""" & Z1 & """+0,DateRange,-1)"

    Sometimes when doubling those quotes gets too much for my eyes, I use:

    Dim Z1 As String
    Z1 = "1/25/99"
    ActiveCell.FormulaR1C1 _
    = "=MATCH(" & chr(34) & Z1 & chr(34) & "+0,DateRange,-1)"



    David wrote:
    >
    > Hi Group,
    > I have some code to do a Match on a date, if the date is hard coded in the
    > formula it works just fine, but i am trying to get that date in via a
    > variable.
    >
    > This works:
    > ActiveCell.FormulaR1C1 = "=MATCH(""1/25/99""+0,DateRange,-1)"
    > but his does not:
    > ActiveCell.FormulaR1C1 = "=MATCH(" & (Z1) & "+0,DateRange,-1)"
    > Z1 is the variable with the same date, but it fails to get the " " around
    > the date and fails.
    >
    > The +0 is not being used currently, but is will be used to find an
    > appromiate date, later in the code, one year later. It is being used in a
    > table with about 5 years worth of data.
    >
    > Thanks,
    >
    > --
    > David


    --

    Dave Peterson

  3. #3
    chijanzen
    Guest

    RE: Date in MATCH formula

    David:

    > ActiveCell.FormulaR1C1 = "=MATCH(" & (Z1) & "+0,DateRange,-1)"


    ActiveCell.FormulaR1C1 = "=MATCH(" & Chr(34) & Z1 & Chr(34) &
    "+0,DateRange,-1)"

    --
    天行健,君*以自強不息
    地勢坤,君*以厚德載物

    http://www.vba.com.tw/plog/


    "David" wrote:

    > Hi Group,
    > I have some code to do a Match on a date, if the date is hard coded in the
    > formula it works just fine, but i am trying to get that date in via a
    > variable.
    >
    > This works:
    > ActiveCell.FormulaR1C1 = "=MATCH(""1/25/99""+0,DateRange,-1)"
    > but his does not:
    > ActiveCell.FormulaR1C1 = "=MATCH(" & (Z1) & "+0,DateRange,-1)"
    > Z1 is the variable with the same date, but it fails to get the " " around
    > the date and fails.
    >
    > The +0 is not being used currently, but is will be used to find an
    > appromiate date, later in the code, one year later. It is being used in a
    > table with about 5 years worth of data.
    >
    > Thanks,
    >
    > --
    > David


  4. #4
    David
    Guest

    RE: Date in MATCH formula

    Thank you very much, worked like a charm.
    --
    David


    "David" wrote:

    > Hi Group,
    > I have some code to do a Match on a date, if the date is hard coded in the
    > formula it works just fine, but i am trying to get that date in via a
    > variable.
    >
    > This works:
    > ActiveCell.FormulaR1C1 = "=MATCH(""1/25/99""+0,DateRange,-1)"
    > but his does not:
    > ActiveCell.FormulaR1C1 = "=MATCH(" & (Z1) & "+0,DateRange,-1)"
    > Z1 is the variable with the same date, but it fails to get the " " around
    > the date and fails.
    >
    > The +0 is not being used currently, but is will be used to find an
    > appromiate date, later in the code, one year later. It is being used in a
    > table with about 5 years worth of data.
    >
    > Thanks,
    >
    > --
    > David


+ 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