Next Leave date

sachin99

New Member
Joined
Jun 18, 2013
Messages
15
Good Day Everyone,

I need a formula to get the next Leave date of an employee based on criteria.

1. Below is the table which shows date on which particular employee is on leave
2. Will enter date in other sheet in cell A2
3. we will also have employee name in this sheet
3. Cell next to employee name should give the next PL date for that employee depending on the date enter in the
Eg. 1. If Sachin is the employee and date enter in Celll A2 is 07-Jan-2018 then value in cell next to Sachin will be 10-Jan-2018

2. If Vikas is the employee and date enter in Celll A2 is 09-Jan-2018 then value in cell next to Sachin will be 12-Jan-2018

3. if the A2 cell is blank then today's date will be consider for calculation

Do let me know if you need any more information on my requirement.

[TABLE="class: outer_border, width: 500"]
<tbody>[TR]
[TD]Date[/TD]
[TD]Sachin[/TD]
[TD]Vikas[/TD]
[/TR]
[TR]
[TD]01-Jan-2018[/TD]
[TD]-[/TD]
[TD]-[/TD]
[/TR]
[TR]
[TD]02-Jan-2018[/TD]
[TD]PL[/TD]
[TD]-[/TD]
[/TR]
[TR]
[TD]03-Jan-2018[/TD]
[TD]PL[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]04-Jan-2018[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]05-Jan-2018[/TD]
[TD][/TD]
[TD]PL[/TD]
[/TR]
[TR]
[TD]06-Jan-2018[/TD]
[TD][/TD]
[TD]PL[/TD]
[/TR]
[TR]
[TD]07-Jan-2018[/TD]
[TD][/TD]
[TD]PL[/TD]
[/TR]
[TR]
[TD]08-Jan-2018[/TD]
[TD][/TD]
[TD]PL[/TD]
[/TR]
[TR]
[TD]09-Jan-2018[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]10-Jan-2018[/TD]
[TD]PL[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]11-Jan-2018[/TD]
[TD]PL[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]12-Jan-2018[/TD]
[TD]PL[/TD]
[TD]PL[/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="width: 196"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]Regards
Sachin

[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi, welcome to the board!

Here is on option you can try to adapt to your actual set-up..:


Excel 2013/2016
ABC
1DateNameNext PL
209/01/2018Sachin10/01/2018
309/01/2018Vikas12/01/2018
Sheet2
Cell Formulas
RangeFormula
C2=INDEX(Sheet1!$A$2:$A$100,MATCH(1,INDEX((Sheet1!$A$2:$A$100>=A2)*(INDEX(Sheet1!$B$2:$C$100,0,MATCH(B2,Sheet1!$B$1:$C$1,0))="PL"),0),0))



Excel 2013/2016
ABC
1DateSachinVikas
201/01/2018--
302/01/2018PL-
403/01/2018PL
504/01/2018
605/01/2018PL
706/01/2018PL
807/01/2018PL
908/01/2018PL
1009/01/2018
1110/01/2018PL
1211/01/2018PL
1312/01/2018PLPL
Sheet1
 
Upvote 0
Hi Sachin,

Try this

[TABLE="width: 387"]
<tbody>[TR]
[TD="colspan: 3"]Sheet 2[/TD]
[/TR]
[TR]
[TD]A Column[/TD]
[TD]B Column[/TD]
[TD]C Column[/TD]
[/TR]
[TR]
[TD]Names[/TD]
[TD]From Date[/TD]
[TD]Next PL leave[/TD]
[/TR]
[TR]
[TD]Sachin[/TD]
[TD]04-Jan-18[/TD]
[TD="align: right"]01/12/2018[/TD]
[/TR]
[TR]
[TD]Vikas[/TD]
[TD]01-Jan-18[/TD]
[TD="align: right"]01/12/2018[/TD]
[/TR]
</tbody>[/TABLE]



Code:

Sub NextPL()


Dim a, b, c As Range
Dim i, lw, lww, j As Integer


lw = Sheets("sheet1").Cells(Sheets("Sheet1").Rows.Count, "A").End(xlUp).Row
lww = Sheets("sheet2").Cells(Sheets("Sheet2").Rows.Count, "A").End(xlUp).Row




For j = 2 To lww
Set a = ThisWorkbook.Sheets("sheet1").Range("A:A").Find(ThisWorkbook.Sheets("sheet2").Cells(j, 2).Value)


a = a.Address


a = Replace(a, "$", "")
a = Right(a, Len(a) - 1) + 1










Set b = ThisWorkbook.Sheets("sheet1").Range("A1:z1").Find(ThisWorkbook.Sheets("sheet2").Cells(j, 1).Value)


b = b.Column - 1


For i = a To lw


If Cells(i, 1).Offset(, b).Value = "PL" Then
ThisWorkbook.Sheets("sheet2").Cells(j, 3).Value = Cells(i, 1).Value
GoTo nextiteration
Else
End If
Next


nextiteration:
Next
End Sub
/>
 
Upvote 0
Hi ,

Thanks for quick and helpful reply...

One more addition to current thread...

can i get the number of leaves applied

Eg.

DateNameNext PL
Sachin
Vikas

<colgroup><col width="25px" style="background-color: rgb(218, 231, 245);"><col><col><col></colgroup><thead>
[TH="align: center"][/TH]
[TH="align: center"]A[/TH]
[TH="align: center"]B[/TH]
[TH="align: center"]C[/TH]

</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]
[TD="align: right"]09/01/2018[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFF00]#FFFF00[/URL] , align: right"]02/01/2018[/TD]

[TD="align: center"]3[/TD]
[TD="align: right"]09/01/2018[/TD]

[TD="align: right"]05/01/2018[/TD]

</tbody>
For Sachin it is 2 and for Vikas it is 4.

Regards
Sachin
 
Upvote 0
Hi, like this maybe.


Excel 2013/2016
ABCD
1DateNameNext PLleaves applied
209/01/2018Sachin02/01/20182
309/01/2018Vikas05/01/20184
Sheet2
Cell Formulas
RangeFormula
D2=COUNTIFS(INDEX(Sheet1!$B$2:$C$100,0,MATCH(B2,Sheet1!$B$1:$C$1,0)),"PL",Sheet1!$A$2:$A$100,"<"&A2)
 
Upvote 0
Hi, like this maybe.

Excel 2013/2016
ABCD
DateNameNext PLleaves applied
Sachin
Vikas

<colgroup><col style="width: 25pxpx"><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]
[TD="align: right"]09/01/2018[/TD]

[TD="align: right"]02/01/2018[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFF00]#FFFF00[/URL] , align: right"]2[/TD]

[TD="align: center"]3[/TD]
[TD="align: right"]09/01/2018[/TD]

[TD="align: right"]05/01/2018[/TD]
[TD="align: right"]4[/TD]

</tbody>
Sheet2

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]D2[/TH]
[TD="align: left"]=COUNTIFS(INDEX(Sheet1!$B$2:$C$100,0,MATCH(B2,Sheet1!$B$1:$C$1,0)),"PL",Sheet1!$A$2:$A$100,"<"&A2)[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]


Hi,

Thanks for the formula...

I try to add new employee name and change the range to from $C$100 to $D$100 and :$C$1 to :$D$1 but it is not giving the desire result.

Can you advise what should i do in this case.

Regards
Sachin
 
Upvote 0
I try to add new employee name and change the range to from $C$100 to $D$100 and :$C$1 to :$D$1

Those amendments look OK.


Excel 2013/2016
ABC
1DateNameCount
209/01/2018Sachin2
309/01/2018Vikas4
409/01/2018Another3
509/01/2018someone else2
Sheet2
Cell Formulas
RangeFormula
C2=COUNTIFS(INDEX(Sheet1!$B$2:$E$100,0,MATCH(B2,Sheet1!$B$1:$E$1,0)),"PL",Sheet1!$A$2:$A$100,"<"&A2)



Excel 2013/2016
ABCDE
1DateSachinVikasAnotherSomeone Else
201/01/2018--PL
302/01/2018PL-
403/01/2018PLPL
504/01/2018
605/01/2018PLPL
706/01/2018PLPL
807/01/2018PL
908/01/2018PLPL
1009/01/2018PL
1110/01/2018PLPL
1211/01/2018PLPLPL
1312/01/2018PLPL
Sheet1
 
Upvote 0
Hi ,


[TABLE="width: 305"]
<colgroup><col><col><col><col span="2"></colgroup><tbody>[TR]
[TD]Date[/TD]
[TD]Sachin[/TD]
[TD]Vikas[/TD]
[TD]Sunil[/TD]
[TD]Raj[/TD]
[/TR]
[TR]
[TD]01-Jan-18[/TD]
[TD] [/TD]
[TD] [/TD]
[TD]PL[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]02-Jan-18[/TD]
[TD]PL[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]03-Jan-18[/TD]
[TD]PL[/TD]
[TD] [/TD]
[TD]PL[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]04-Jan-18[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]05-Jan-18[/TD]
[TD] [/TD]
[TD]PL[/TD]
[TD] [/TD]
[TD]PL[/TD]
[/TR]
[TR]
[TD]06-Jan-18[/TD]
[TD] [/TD]
[TD]PL[/TD]
[TD] [/TD]
[TD]PL[/TD]
[/TR]
[TR]
[TD]07-Jan-18[/TD]
[TD] [/TD]
[TD]PL[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]08-Jan-18[/TD]
[TD] [/TD]
[TD]PL[/TD]
[TD]PL[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]09-Jan-18[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]PL[/TD]
[/TR]
[TR]
[TD]10-Jan-18[/TD]
[TD]PL[/TD]
[TD] [/TD]
[TD] [/TD]
[TD]PL[/TD]
[/TR]
[TR]
[TD]11-Jan-18[/TD]
[TD]PL[/TD]
[TD] [/TD]
[TD]PL[/TD]
[TD]PL[/TD]
[/TR]
[TR]
[TD]12-Jan-18[/TD]
[TD]PL[/TD]
[TD]PL[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]13-Jan-18[/TD]
[TD] [/TD]
[TD]PL[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
</tbody>[/TABLE]


Below is the output of all formulas


[TABLE="width: 342"]
<colgroup><col><col><col><col><col></colgroup><tbody>[TR]
[TD]Date[/TD]
[TD]Employee[/TD]
[TD]Next PL[/TD]
[TD]Count Of PL[/TD]
[TD]Actual PL Count[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Vikas[/TD]
[TD="align: right"]05-Jan-18[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]4[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Sachin[/TD]
[TD="align: right"]02-Jan-18[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Sunil[/TD]
[TD="align: right"]01-Jan-18[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Sher[/TD]
[TD="align: right"]05-Jan-18[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]2[/TD]
[/TR]
</tbody>[/TABLE]


Count of PL "=COUNTIFS(INDEX(Sheet1!$B$2:$E$100,0,MATCH(B2,Sheet1!$B$1:$E$1,0)),"PL",Sheet1!$A$2:$A$100,"<"&A2)"

The formula is not giving correct output as from next PL there are 4 PL for Vikas and 3 for Sachin and so on.
Can you check and advise is i am doing anything wrong or there is issue with formula.

Regards
 
Upvote 0
Hi ,

Thanks for the formula,

i tried to update the formula in but still it is not giving the desire output to me.. can you share a excel file with me with formula.

Thanks !..

Regards
Sachin
 
Upvote 0
can you share a excel file with me with formula

Hi, what you can see in post 7 is a screen shot of the Excel file with the formula implemented.

still it is not giving the desire output to me..

What output are you getting?
- Is it an error? If so what is the error?
- Is it simply the wrong result? If so, can you post example data that demonstrates this and state what the correct result should be?
- Is it something else? If so, what are the details?

If your layout is different to post 7 and you have attempted to alter the formula to your actual set-up then post the formula that you are trying and describe in detail your exact layout.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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