Attached is an interim solution which has a few riders; I'm not at my usual computer and have developed this with Exel2003 on a Windows XP machine, so there are several things which may not work:
1. This is a .xls file, not .xlsx (you should have no trouble opening it)
2. In the VBE there is a reference set to
Microsoft ActiveX Data Objects 2.7 Library. This may be
missing from your machine in which case choose another version of the same reference. It might work.
3. You will probably have to save your
Copy of MasterFile.xlsx as
Copy of MasterFile.xls (that is, as an Excel 97 to 2003 file, or something like that)
4. You
might be able to avoid points 2 & 3 above if you change the connection string in the code (it's the line beginning
sConnect =) to something more like:
Code:
sConnect = "ODBC;DBQ=C:\Users\zzzzzz\Documents\Copy of MasterFile.xlsx;Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DriverId=1046;FIL=excel 12.0;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;ReadOnly=1;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"
5. Don't forget to update the file and path name of the MasterFile in the code (same line).
There are two buttons on the sheet, the only difference being how the start and end dates are obtained.
The solution is not a SQL-only solution; 3 SQL queries are used in the code and the resulting recordsets are used to create an array which is placed on the worksheet.
The solution only gives
Emp Names where there are LOP days. Any names not appearing means they have no LOP days.
How it's supposed to work:
Get list of names to process (SQL)
For each name:
Get list of Dates and Hours where:WEEKOFF-OF,Approved,Hours>=8 for the day, and nothing else on that date (SQL)
Get list of Dates and Hours where:UNPAID-ABS,Approved,Hours>=8 for the day, and nothing else on that date (SQL)
Run through the WEEKOFF-OF dates looking for runs of sequential dates, and when one is found check that there are UNPAID-ABS on the day before and the day after that run (a run can be only one day long), and if there are, count those WEEKOFF-OF days as LOP, but only those dates between start and end dates. These data are put into an array.
When the names have all been processed, the array is written to the sheet.
I intend to re-write for Excel 2010-2016 when I get to a machine with it on. That may not be for a week or three.
Anyway, something for you to play with.