+ Reply to Thread
Results 1 to 2 of 2

Get enddatetime if X no. of working hours is added to startdatetime

  1. #1
    Registered User
    Join Date
    10-24-2020
    Location
    singapore
    MS-Off Ver
    365
    Posts
    1

    Get enddatetime if X no. of working hours is added to startdatetime

    Hi I am facing difficult in getting the correct enddate time.
    Please refer to my attachment. Those in Red are populating the wrong enddatetime. Can help to check my vba function?


    This are the criteria:

    1: Working hours for Weekday 8.30 am to 5.30 pm excluding lunch break from 12 pm to 1 pm
    2: Working hours for Weekends / PH is from 8.30 am to 12.30 pm (no lunch)

    My intention is to get the enddatetime if X no. of working hours is added to the startdatetime.
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    09-18-2023
    Location
    Geogia, USA
    MS-Off Ver
    365
    Posts
    168

    Re: Get enddatetime if X no. of working hours is added to startdatetime

    A couple of observations, without changing your code too drastically.

    Please Login or Register  to view this content.
    see my notes in the comments for checking for a holiday, I consolidated the Ifs a bit and you were comparing a date to a Boolean which would
    not work. You were checking startDate = isHoliday, when you just needed If isHoliday.

    Also check out the notes on the usage of the Hour function, where you seem to expect it to know what a 1/2 hour is, as it returns "whole number between 0 and 23"
    You're comparing it to 8.5 and 12.5, if you want to know if it is greater then 8.5 you need to check hour and minutes of the currentDateTime.

    I'm a bit confused as to the loop and why you'd add 12 hours (so 1pm becomes 1am) as the end of the code.

    I hope this makes sense, give your code another pass and use debugging to check the values as the code runs. https://www.excel-easy.com/vba/examples/debugging.html

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 12-05-2018, 01:46 AM
  2. [SOLVED] Calculate time for working hours when start time falls outside of working hours
    By SKDY_Beau in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-20-2014, 12:50 PM
  3. Replies: 3
    Last Post: 10-10-2013, 10:15 PM
  4. Elapsed working hours, without counting weekends or non-working hours
    By ebkiwi in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-16-2013, 04:18 PM
  5. [SOLVED] Calculate hours with predefined Working Hours and Weekend Hours
    By garciapliz in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-05-2013, 11:17 AM
  6. Replies: 2
    Last Post: 06-14-2013, 10:45 AM

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