Forum Discussion
Luxio1997
Feb 15, 2023Brass Contributor
Automatic entry of times based on conditions
Hello everyone. For weeks now, I've been going crazy looking for a way to solve the problem I'm about to present to you. I have attached the sheet I prepared. In the "HOUR" column there is a...
SnowMan55
Feb 18, 2023Bronze Contributor
Yes, it can be done with just formulas. Limitations and assumptions:
- The formulas for column C rely on the fact that the last time for each Sunday schedule is after 18:00, and the other times are all before 18:00.
- Google reports that Summer Time in Italy will run from 02:00 26-Mar through 03:00 29-Oct. I placed those start and end dates in cells M1 and M2, but you could put them elsewhere, with appropriate changes to the column D formulas.
- You must manually enter the starting date into C4. If this date is a Sunday, you must manually enter the first time from the appropriate Sunday schedule into D4; otherwise, D4 should be blank.
- The formulas work for (basically) one calendar year only. This is because I have only one date range for determining Summer Time. However, you can remove this limitation if you move them to a separate worksheet, make a lookup table based on the year of the date in column C, and change the column D formulas appropriately. (Yes, I did extend the formulas out to row 525, and those calculations are valid, as the generated dates do not reach the 2024 start of Summer Time.)
Within the column D formula:
- Most of the complexity is in determining which of the three Sunday schedules to use. The appropriate range of cells is assigned to intermediate variable SundayRng.
- DayCt is the number of times the date in column C for this row has appeared (so far). DayCt is used as an index into the appropriate Sunday schedule.
--for C5 (the first calculated date):
=IF( D4="", C4+1, IF(D4>TIME(18,0,0), C4+1, C4) )
--for D5 (the first calculated time-of-day):
=IF( WEEKDAY(C5,1)<>1, "", LET(MonthNum, MONTH(C5), DayCt, COUNTIF(C$3:C5,C5), SundayRng, IF(OR(MonthNum=7,MonthNum=8),N$4:N$5,IF(AND(C5>=M$1,C5<M$2),M$4:M$7,L$4:L$7)), LookupTime, INDEX(SundayRng,DayCt), LookupTime) )
- Luxio1997Feb 18, 2023Brass ContributorHi SnowMan55, beautiful solution but I have a problem: I checked and this formula doesn't exist in the Office 2013 package. How can we fix it?
- HansVogelaarFeb 18, 2023MVP
In D5:
=IF( WEEKDAY(C5,1)<>1, "", INDEX(IF(OR(MONTH(C5)={7,8}),N$4:N$5,IF(AND(C5>=M$1,C5<M$2),M$4:M$7,L$4:L$7)),COUNTIF(C$3:C5,C5)))
Fill down. See attached version.
- Luxio1997Feb 18, 2023Brass ContributorHi Hans, great answer.
Now there is another problem: in column C (the date column) there is the formula (for example in C5):
=IF( D4="", C4+1, IF(D4>TIME(18,0,0), C4+1, C4) )
This creates the problem that D4 will never be empty because every day there will always be times.
What can be the solution?