+ Reply to Thread
Results 1 to 7 of 7

No of years and months from decimals

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

    No of years and months from decimals

    Hi All

    How to convert decimals into years. For example i have my result as 1.5 , 1.58 , 1.41 and so on...

    my message box should show 1Year . 6months, 1year.7months and so on.
    how to write a vba code

    Many thnx

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,604

    Re: No of years and months from decimals

    Hi...
    You can use this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Now, you will have this result:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    As you can see 1,5 will give you 1 year, 06 months
    but 1,58 will give you 1 year, 0,696 monhts.
    If you want to round 0696 to 07 months then round result on 2 decimal places.

    Is this OK for you?

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

    Re: No of years and months from decimals

    Actually i am trying to convert calculate the number of days through a application.inputbox. I could manage for the number of days and months, but could not do that for the number of years. look into the code below.

    For example if it is 37 months the third message box should show 3years.1month

    Please note few variables have been declared just like that. i am very naive to processing . so my code might look bit horrible, Sorry guys.


    Please Login or Register  to view this content.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: No of years and months from decimals

    That's very ambiguous.

    How many months and days are there from Jan 31 to Mar 1? From Jan 31 to 28 Feb?
    Entia non sunt multiplicanda sine necessitate

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

    Re: No of years and months from decimals

    Looks like i require i have to change the coding for months also. i know it should be 31 days on average. however for february i am quite not sure how to alter the code any suggestions

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: No of years and months from decimals

    I dunno either. There's no way to calculate time differences like that that doesn't have anomalies.

    Elapsed days is unambiguous.

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

    Re: No of years and months from decimals

    look at my other post, i am somehow managed to solve the issue, my post name is calculation of years and months

+ 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