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.

DateSachinVikas
01-Jan-2018--
02-Jan-2018PL-
03-Jan-2018PL
04-Jan-2018
05-Jan-2018PL
06-Jan-2018PL
07-Jan-2018PL
08-Jan-2018PL
09-Jan-2018
10-Jan-2018PL
11-Jan-2018PL
12-Jan-2018PLPL

<tbody>
</tbody>

Regards
Sachin


<colgroup><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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

Sheet 2
A ColumnB ColumnC Column
NamesFrom DateNext PL leave
Sachin04-Jan-1801/12/2018
Vikas01-Jan-1801/12/2018

<tbody>
</tbody>



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.

ABC
1DateNameNext PL
209/01/2018Sachin02/01/2018
309/01/2018Vikas05/01/2018

<colgroup><col width="25px" style="background-color: rgb(218, 231, 245);"><col><col><col></colgroup><thead>
</thead><tbody>
</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
1DateNameNext PLleaves applied
209/01/2018Sachin02/01/20182
309/01/2018Vikas05/01/20184

<colgroup><col style="width: 25pxpx"><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet2

Worksheet Formulas
CellFormula
D2=COUNTIFS(INDEX(Sheet1!$B$2:$C$100,0,MATCH(B2,Sheet1!$B$1:$C$1,0)),"PL",Sheet1!$A$2:$A$100,"<"&A2)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>


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 ,


DateSachinVikasSunilRaj
01-Jan-18 PL
02-Jan-18PL
03-Jan-18PL PL
04-Jan-18
05-Jan-18 PL PL
06-Jan-18 PL PL
07-Jan-18 PL
08-Jan-18 PLPL
09-Jan-18 PL
10-Jan-18PL PL
11-Jan-18PL PLPL
12-Jan-18PLPL
13-Jan-18 PL

<colgroup><col><col><col><col span="2"></colgroup><tbody>
</tbody>


Below is the output of all formulas


DateEmployeeNext PLCount Of PLActual PL Count
Vikas05-Jan-1804
Sachin02-Jan-1803
Sunil01-Jan-1801
Sher05-Jan-1802

<colgroup><col><col><col><col><col></colgroup><tbody>
</tbody>


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,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

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