Active Member
March 25, 2023
Hello everyone
I want to find and have in one cell the periods that a person used sick leave (for record purposes) in the month (see the example below). I've tried to find something online, but haven't succeeded. I need it to be in one cell due to report reasons at the end of the month (among other things).
By the way, I need it for excel 2010 (even though the example is in excel 2019).
For example:
A1 to AE1 dates from Jan 1 to Jan 31
Cells D2, E2, F2, N2, O2, P2, Q2, W2, X2, Y2, and Z2 have the letter S, which indicates the day person was on sick leave.
I need cell AF2 to have the following
Jan 4-Jan 6, Jan 14-Jan17, Jan 23-Jan 26.
Active Member
February 25, 2023
Hi,
I can't see the attached document. If i'm not misinterpreting
A1 to AE1 dates from Jan 1 to Jan 31 (31 dates)
However, for February 2023, the dates are from 1 to 28 and are in the range of A1 : AB1.
In this case, assuming AC1 : AE1 = "" or Empty Cells
Please try (in cell AF2)
=SUMPRODUCT(($A$1:$AE$1<>"")*($A2:$AE2="S"))
Active Member
March 25, 2023
Hello Janset Beyaz
Thanks for the reply. And yes, you are right, if it's February, then AC1:AE1 would be empty.
I don't know why you can't see the attached document (trying again), but your formula is given the number of sick days. What I need is the periods of sick leave (dates from ... to..., or I need cell AF2 to have the following: Jan 4-Jan 6, Jan Jan 14-Jan17, Jan 23-Jan 26).
Trusted Members
October 17, 2018
Active Member
February 25, 2023
Hi,
If your Excel version is Excel365 and you have DROP, MAP, LAMBDA, HSTACK (in addition to these, REDUCE and VSTACK for auto spill in the range) functions, write the following formula in cell AF2 and try. (If you don't have these functions we have to wait for Hans Hallebeck's solution)
=LET(f,FILTER($A$1:$AE$1,($A$1:$AE$1<>"")*(A2:AE2="S")),a,HSTACK(-1,f,-1),b,COLUMNS(a),c,SEQUENCE(,b-2,2),IFERROR(TEXTJOIN(", ",,MAP(c,LAMBDA(x,IF(INDEX(a,x-1)+1=INDEX(a,x),"",LET(k,MATCH(0,--(DROP(a,,x)=SEQUENCE(,b-x,INDEX(a,1,x)+1)),0)-1,TEXT(INDEX(a,x),"mmm dd")&IF(k=0,"","-"&TEXT(INDEX(a,x)+k,"mmm dd"))))))),""))
Moreover, suppose you have data in the range A2 : AE9. Copy the above formula down to AF9..
If you want auto spill in the range with formula in single cell, first delete the range AF2:AF9 and
formula in cell AF2 and try..
=LET(rng,A2:AE9,d,A1:AE1,s,SEQUENCE(ROWS(rng)),DROP(REDUCE(0,s,LAMBDA(x,y,VSTACK(x,LET(f,FILTER(d,(d<>"")*(INDEX(rng,y,0)="S")),a,HSTACK(-1,f,-1),b,COLUMNS(a),c,SEQUENCE(,b-2,2),IFERROR(TEXTJOIN(", ",,MAP(c,LAMBDA(q,IF(INDEX(a,q-1)+1=INDEX(a,q),"",LET(k,MATCH(0,--(DROP(a,,q)=SEQUENCE(,b-q,INDEX(a,1,q)+1)),0)-1,TEXT(INDEX(a,q),"mmm dd")&IF(k=0,"","-"&TEXT(INDEX(a,q)+k,"mmm dd"))))))),""))))),1))
1 Guest(s)