+ Reply to Thread
Results 1 to 6 of 6

date calculations

  1. #1
    Forum Contributor
    Join Date
    02-12-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    261

    date calculations

    Hi All


    I am trying to write a vba code for calcuating dates. While the details are as follows

    A1 : 01-05-2013
    B1: 2 (2 being the number of years)
    C1 : I have inserted a date formula : DATE(YEAR(A1)+B1,MONTH(A1),DAY(A1)-1)

    So that in C1 i can have 30 -04-2015 which is 1 day less than the Exactly two years. While i try to write the same at VBA level it doesnt work.


    Please Login or Register  to view this content.
    Help Required please. I have an exam tomrrow
    Last edited by grkchakri; 05-06-2013 at 08:39 AM. Reason: TO ASK THE QUESTION CORRECTLY

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: date calculations

    The basic format/syntax is

    Range("G6").FormulaR1C1 = "=DATE(YEAR(R[-5]C[-6])+R[-5]C[-5],MONTH(R[-5]C[-6]),DAY(R[-5]C[-6])-1)"

    Where the R[] and C[] values are references to cells relative to the target cell.
    Elegant Simplicity............. Not Always

  3. #3
    Forum Contributor
    Join Date
    02-12-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    261

    Re: date calculations

    If my understanding is write with the regards the above code

    in G6 It will calculate the date given ROW 5 AND COLUMN 6 WHICH IS F5 , AM I RIGHT.
    But still doesnt seem when i am trying to input the code as . what is the incorrect thing in the below code

    Please Login or Register  to view this content.

    Many thanx for your help.

  4. #4
    Forum Contributor ragavan.sridar1's Avatar
    Join Date
    11-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010, Excel 2003
    Posts
    208

    Re: date calculations

    NO,

    it is -5 rows from G6, "-" indicates the backward row.

    so here it refers to a1.

    Give the formula in your module code give it a try..
    Thanks!
    Raga.

    Please,mark your thread [SOLVED] if you received your answer.

    Click the little star * below, to give some Rep if you think an answer deserves it.

    I learnt so many things from these links.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: date calculations

    Change Date to DateSerial.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  6. #6
    Forum Contributor
    Join Date
    02-12-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    261

    Re: date calculations

    See below the comments updated by Norie and its working for me. Thats is simpler and easier to understand. But Thankx for your help and giving me your inputs.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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