Skip to content

Instantly share code, notes, and snippets.

@lionrajkumar
Created January 14, 2026 11:34
Show Gist options
  • Select an option

  • Save lionrajkumar/5e01f6b2f9d96b44b4bd0af994627045 to your computer and use it in GitHub Desktop.

Select an option

Save lionrajkumar/5e01f6b2f9d96b44b4bd0af994627045 to your computer and use it in GitHub Desktop.

You want the next task start date to depend on whether there are remaining hours left on the previous task’s end date.


Logic (very important)

  • 8 hours = 1 workday
  • If previous task hours is a multiple of 8 → no remaining hours → next task starts next working day
  • If previous task hours is NOT a multiple of 8 → remaining hours exist → next task starts the SAME day
  • Weekends must be skipped

Final Excel Setup

Columns

A = Hours
B = Start Date
C = End Date

1️⃣ End Date Formula (Column C)

C2

=WORKDAY(B2, CEILING(A2/8,1)-1)

Copy down.


2️⃣ Start Date Formula (Column B – Row 3 onward)

B3

=IF(MOD(A2,8)=0, WORKDAY(C2,1), C2)

Copy down.


Why this works

  • MOD(A2,8)=0 → task used full days only
  • WORKDAY(C2,1) → start next weekday
  • C2 → reuse same day if hours remain

✅ Result (Your Required Behavior)

hrs st date end date
8 15-Jan 15-Jan
16 16-Jan 19-Jan
12 20-Jan 21-Jan
24 21-Jan 26-Jan

Examples explained

  • Row 2 (16 hrs) → full 2 days → Row 3 starts next day
  • Row 3 (12 hrs) → 1.5 days → 4 hrs left → Row 4 starts same day
@lionrajkumar
Copy link
Author

To include holidays in the calculation, we’ll need to update the WORKDAY formulas to skip the specified holidays. Excel allows us to specify holidays as a range of dates.

Holiday List:

  • 26-Jan
  • 14-Apr
  • 01-May

Solution

Steps:

  1. Create a holiday list in Excel somewhere (e.g., E1:E3)
  2. Update the formulas to account for the holidays.

1️⃣ Set Up Holiday List

You can place your holiday dates in cells, say E1:E3:

E1: 26-Jan
E2: 14-Apr
E3: 01-May

2️⃣ Updated Formula for End Date (Column C)

Now, we’ll modify the End Date formula in C2 to exclude holidays.

In C2, use this updated formula:

=WORKDAY(B2, CEILING(A2/8,1)-1, $E$1:$E$3)

This tells Excel to:

  • Use the WORKDAY function as before
  • Skip any holidays listed in range $E$1:$E$3

Copy this formula down the column.


3️⃣ Updated Formula for Start Date (Column B)

Now for the Start Date formula in B3:

=IF(MOD(A2,8)=0, WORKDAY(C2,1, $E$1:$E$3), C2)

This ensures:

  • The start date skips weekends and holidays.
  • If there's any remaining time, it starts the same day.

Again, copy this down for subsequent rows.


Result with Holidays Considered

hrs st date end date
8 15-Jan 15-Jan
16 16-Jan 19-Jan
12 20-Jan 21-Jan
24 21-Jan 26-Jan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment