+ Reply to Thread
Results 1 to 5 of 5

adding days/hours automatically to date time using a macro

  1. #1
    Registered User
    Join Date
    05-15-2011
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    12

    adding days/hours automatically to date time using a macro

    Hi all,

    I need to write a fairly complex formula in Excel to do with time and dates.

    In Column A I will have the 'Type': either Red or Blue.

    In Column B, the 'Date purchase date and time.'

    And Column C is the 'Due date and time.' Column C is where the formula needs to be.

    Red Type.
    A "Red" type means it is due in 1 hour. So if the time is 10am, the time needs to be set to 11am in the due date and time column. However if the purchase time is after 3.01pm, the due time needs to be set to 9am the next day. I.e 3pm will equate to 4pm, however 3.01pm will mean it is due the next day at 9am.

    THis is where it gets tricky.... if the date is on the Friday after 3pm, Saturday all day, or Sunday all day, the due date needs to be set to the monday after at 9am.

    Blue Type.
    A "Blue" type means it is due in 24 hours. So the time and date need to be set to 24 hours later. If it is received on a Friday it should be set to the same time on the Monday.

    SO a normal week day i.e Tuesday 11am will be due on Wednesday at 11am.

    So 2pm on the Friday received, equates to being due on the Monday at 2pm. Saturday 2pm, equates to Monday 2pm, Sunday 2pm equates to Monday 2pm.

    I have attached an Excel spreadsheet with samples of how the results should look.

    Thanks in advance!

    Paul
    Attached Files Attached Files

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: adding days/hours automatically to date time using a macro

    Paul,

    based solely on the examples provided...

    Please Login or Register  to view this content.
    the above replicates your expected results.

    Note use of NETWORKDAYS & WORKDAY functions necessitates activation of the Analysis ToolPak (aka ATP) Add-In (Tools -> Add-Ins).

    If you are doing a lot of date based calculations I would strongly advise installing this as it will simplify your calculations.

    You can achieve the same without ATP, however, should you wish/need to incorporate Public Holidays into the above then things become a little convoluted.
    If you don't need to worry about Public Holidays then you can avoid ATP functions quite simply:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-15-2011
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: adding days/hours automatically to date time using a macro

    DonkeyOte,

    thanks so much!!! seems to be working perfectly cheers!!!

  4. #4
    Registered User
    Join Date
    05-15-2011
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: adding days/hours automatically to date time using a macro

    Hi DonkeyOte,

    The result is working perfectly but I am trying to better understand the formula you gave me...

    How does it add 24 hours if it is not Red???

    Once again, it is doing exactly what it is meant to do but I can't work out how you got it to add 1 day from that formula.... (I am using the second formula as I do not have the analysis pack)

    I can't find that part in the formula and its driving me crazy!

    Thanks a lot,

    Dexter

    Quote Originally Posted by DonkeyOte View Post
    Paul,

    based solely on the examples provided...

    Please Login or Register  to view this content.
    the above replicates your expected results.

    Note use of NETWORKDAYS & WORKDAY functions necessitates activation of the Analysis ToolPak (aka ATP) Add-In (Tools -> Add-Ins).

    If you are doing a lot of date based calculations I would strongly advise installing this as it will simplify your calculations.

    You can achieve the same without ATP, however, should you wish/need to incorporate Public Holidays into the above then things become a little convoluted.
    If you don't need to worry about Public Holidays then you can avoid ATP functions quite simply:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-15-2011
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: adding days/hours automatically to date time using a macro

    Sorry ignore my post, I worked it out!!! The array, if weekday add 1, if Fri or Sat add 3 and 2....

    Very clever,

    Cheers!!!

+ 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