Hello CharlieBeth,
It still does not seem to find everyone, such as Emp No 210611 whose absence ran from 03/07/2017 to 22/03/2018
As you are setting two date parameters to work within, the code will only work within these two date parameters. Your above quoted example was never going to show up because you have set the date parameters in the sample file as being 18/03/2018 (start) to 24/03/2018 (end). The additional "tweaks" in the last code I supplied almost got us there but there is no point in setting parameters if you intend to work outside those parameters. If you look closely at the All Absences sheet, you will see that some start dates(Column P) are greater than the end dates (Column Z) so this just confuses the issue further. One example is row 58: the start date is noted as 10/01/2018 and the end date is 12/01/2017!!
For your particular situation, I would suggest that you use an "aging" method. By this, for example, I mean absences up to seven days, then between seven and fourteen days, then between fourteen and thirty days and then greater than thirty days. These could be colour coded in the All Absences sheet and then the relevant rows of data can be transferred to the This Week sheet based on colour for any analysis that you may have to do for the various time periods.
I have attached your sample file again with this type of method implemented.
Firstly, I have inserted a column in both worksheets(AA).
Secondly, the following code is placed in the ThisWorkBook module:-
This code will insert a formula in each cell in Column AA which will, in turn, give us the number of days between the start and end dates. The code will then colour the cells in Column AA with colours that represent the different time periods: up to seven days, a pale blue colour. Up to fourteen days, green. Up to thirty days, cyan. Greater than thirty days, yellow. Cells in Column Z without values will leave the adjacent cells in Column AA white (these are the absentees yet to return).
In some white cells you will see a #NUM! reference message. This will appear because of the problem I mentioned above about some start dates (Column P) being greater than the end dates (Column Z). You may want to address this in your actual workbook. The formula simply will not calculate the reverse order seeing that it is incorrect.
Thirdly, the following codes are placed in one standard module:-
These codes are assigned to the buttons (in similar colours to the coloured cells in the All Absences sheet, Column AA) in the This Week sheet.
You'll note that the codes are very similar but just reference the different colours. Click on any button in the sample file to have the relevant data transferred to the This Week sheet. I've named the buttons to refer to the different time periods.
I hope that this helps.
Cheerio,
vcoolio.
Bookmarks