+ Reply to Thread
Results 1 to 2 of 2

Using DATE in VBA, gives error

  1. #1
    Andreas Palm (HP C&I .NET)
    Guest

    Using DATE in VBA, gives error

    Range("L" & c).Select
    With Selection
    .FormulaR1C1 = "DATE(YEAR(""" & t & """);" & "MONTH(""" & t & """)+" & b & " ;" & "DAY(""" & t & """))"
    End With


    What I try to do is this

    .FormulaR1C1 = "=DATE(YEAR(""" & t & """);" & "MONTH(""" & t & """)+" & b & " ;" & "DAY(""" & t & """))"


    However as soon as I put "=" in the code I get an error. Without the "=" the cells get filled with this:


    DATE(YEAR("01.01.2005");MONTH("01.01.2005")+2 ;DAY("01.01.2005"))

    if in the cell I put the "=" in front of this text I get exactly what I want => 01.03.2005


    So why do I get an error in the code, if when I change the code later manually the formula is correct.


    best regards
    andreas


  2. #2
    Tom Ogilvy
    Guest

    Re: Using DATE in VBA, gives error

    VBA uses US delimiters and so forth for formula and formulaR1C1 so use a
    comma instead of a semicolon

    t = Application.Replace(t,".","/")
    .FormulaR1C1 = "=DATE(YEAR(""" & t & """)," & "MONTH(""" & t &
    """)+" & b & " ," & "DAY(""" & t & """))"

    You also might have problems with month/day sequencing.

    --
    Regards,
    Tom Ogilvy

    "Andreas Palm (HP C&I .NET)" <[email protected]> wrote in message
    news:[email protected]...
    > Range("L" & c).Select
    > With Selection
    > .FormulaR1C1 = "DATE(YEAR(""" & t & """);" & "MONTH(""" & t &

    """)+" & b & " ;" & "DAY(""" & t & """))"
    > End With
    >
    >
    > What I try to do is this
    >
    > .FormulaR1C1 = "=DATE(YEAR(""" & t & """);" & "MONTH(""" & t &

    """)+" & b & " ;" & "DAY(""" & t & """))"
    >
    >
    > However as soon as I put "=" in the code I get an error. Without the "="

    the cells get filled with this:
    >
    >
    > DATE(YEAR("01.01.2005");MONTH("01.01.2005")+2 ;DAY("01.01.2005"))
    >
    > if in the cell I put the "=" in front of this text I get exactly what I

    want => 01.03.2005
    >
    >
    > So why do I get an error in the code, if when I change the code later

    manually the formula is correct.
    >
    >
    > best regards
    > andreas
    >




+ 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