Calculation when 3 conditions are met

Fidbeck

New Member
Joined
Oct 11, 2023
Messages
11
Office Version
  1. 365
Platform
  1. MacOS
  2. Web
Hello guys,

This is my first post, so sorry in advance if something is not correct
I'm creating an excel where I keep track of the hours I have worked in a specific month, I also have to keep track of how many of those hours are considered as being day and night hours (night hours go from 21:00 to 06:00 (PM and AM respectively))

At great pain, I've come with this formula to calculate how many hours of the work journey that are considered as night
Excel Formula:
=IF(F3="OFF";"";MOD(G3-F3;1)*24-(G3<F3)*(21-6)-MEDIAN(G3*24;6;21)+MEDIAN(F3*24;6;21))
Cells F3 and G3 are formatted as Time.
If I work from 23:00 to 08:00 it shows a 9 hour working journey and 7 of those hours considered as night. (To calculate the hours that are considered as day, I simply subtract the night hours to the total amount of the work journey).
If the day is OFF, it doesn't calculate anything.

But... there was a day where I had to work more than once. From 03:00 to 04:00 (AM both) and from 21:00 to midnight. The sum should show 4 hours. I edited the formula to accommodate both hours like this
Excel Formula:
=IF(F5="OFF";"";MOD(G5-F5;1)*24-(G5<F5)*(21-6)-MEDIAN(G5*24;6;21)+MEDIAN(F5*24;6;21))+IF(H5="";"";MOD(I5-H5;1)*24-(I5<H5)*(21-6)-MEDIAN(I5*24;6;21)+MEDIAN(H5*24;6;21))

But the thing is that I have to do copy and paste this formula every time I work moth than once in the same day, so what I'm asking you guys is if you guys can help me reformulate this formula in order to automatically do the calculation if 3 conditions are met.


1st - If the 1st cell (F3) is "OFF", it doesn't do anything
2nd - If cells H3 and I3 (or as long as one is empty) are empty is calculates only the values in F3 and G3.
3rd - If there are values in all cells (F3 to I3) it should calculate all cells.

Ps.: Some things are in my language which is Portuguese, so you many not understand everything but what's important, you will understand
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
welcome to the forum. Would you be kind enough to post some of your data. Please anonymize it for personal/protected data.
 
Upvote 0
Do I need to install that XL2BB add-in?
I'm not being able to install it...
 
Upvote 0
InOutSum1614
SQui21 de setembro07:00:0015:00:00 8:0080
SSex22 de setembro09:00:0015:00:006:0060
FSSáb23 de setembro03:00:0004:00:0021:00:0003:00:007:0007
FSDom24 de setembroOFF0:00
SSeg25 de setembro23:00:0008:00:009:0027
0:0000
 
Upvote 0
Livro1.xlsx
CDEFGHIJKL
2InOutSum1614
3SQui21 de setembro07:00:0015:00:00 8:0080
4SSex22 de setembro09:00:0015:00:006:0060
5FSSáb23 de setembro03:00:0004:00:0021:00:0003:00:007:0007
6FSDom24 de setembroOFF0:00  
7SSeg25 de setembro23:00:0008:00:009:0027
80:0000
Folha1
Cell Formulas
RangeFormula
K2:L2K2=SUM(K3:K7)
C3:C7C3=IFS(A3=1,"F",D3="Sáb","FS",D3="Dom","FS",D3="Seg","S",D3="Ter","S",D3="Qua","S",D3="Qui","S",D3="Sex","S")
D3:D7D3=CHOOSE(B3,"Seg","Ter","Qua","Qui","Sex","Sáb","Dom")
E3E3=DATE(Folha4!$E$4,1,Folha4!F5)+243
E4:E7E4=E3+1
J3:J4,J8J3=IF(F3="FOLGA",0,MOD(G3-F3,1))
K3:K7K3=IF(F3="OFF","",(J3*24)-L3)
L3:L4,L8L3=IF(F3="FOLGA","",MOD(G3-F3,1)*24-(G3<F3)*(21-6)-MEDIAN(G3*24,6,21)+MEDIAN(F3*24,6,21))
J5J5=IF(F5="FOLGA",0,MOD(G5-F5,1)+MOD(I5-H5,1))
L5L5=IF(F5="OFF","",MOD(G5-F5,1)*24-(G5<F5)*(21-6)-MEDIAN(G5*24,6,21)+MEDIAN(F5*24,6,21))+IF(H5="","",MOD(I5-H5,1)*24-(I5<H5)*(21-6)-MEDIAN(I5*24,6,21)+MEDIAN(H5*24,6,21))
J6:J7J6=IF(F6="OFF",0,MOD(G6-F6,1))
L6:L7L6=IF(F6="OFF","",MOD(G6-F6,1)*24-(G6<F6)*(21-6)-MEDIAN(G6*24,6,21)+MEDIAN(F6*24,6,21))
K8K8=IF(F8="FOLGA","",(J8*24)-L8)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G7Expression=$F7="FOLGA"textNO
H5Expression=$F5="FOLGA"textNO
F3:F7Expression=$F3="FOLGA"textNO
C3:L7Expression=$C3="FS"textNO
C3:L7Expression=$C3="S"textNO
C3:L7Expression=$A3=1textNO
 
Upvote 0
I wasn't sure Mac Excel would work with xl2bb add in. So, Thanks very much for getting it.

However, you also need to post some data from worksheet folha4. Thanks.
 
Upvote 0
I'm terribly sorry for the excessive number of posts, I'm not being able to work with this... Never know which of the options is best.... Fell free to delete some of them

BTW FOLGA = OFF

Contribuições
Valor hora4.99 $
Val. H. noturna6.24 $25.00%
Descontos SegSoc11.00%
FS5.00%
F20.00%
Horas contrato64:00
Hora extra5%
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top