+ Reply to Thread
Results 1 to 15 of 15

Formula to Calculate Occurrences of Staff Absence

  1. #1
    Registered User
    Join Date
    09-10-2014
    Location
    Hertfordshire, England
    MS-Off Ver
    2010
    Posts
    14

    Formula to Calculate Occurrences of Staff Absence

    Hello everyone,

    I hope you can help, as I've exhausted both the limit of my knowledge of arrays, and endless searching to solve this.

    I have created a major spreadsheet to track staff sickness absences (I have attached a very basic example here.) Counting the numbers of days is the easiest thing. I also need to capture the number of occurences within a year (so, if sick for an entire week, or fortnight, that's one occurrence - fairly standard Absence Management, I think.)

    I've finally managed to get a formula that counts the number of occurences for full-time staff, and to ignore weekends that fall within a period of absence (i.e if someone is sickness on a Friday and trhe following Monday.) None of the staff works weekends. I've included that formula in the example.

    The difficulty I face is that some staff have days within the week that they don't work, so cannot be included as a day sick. Some staff don't work Monday each week, some Thursday etc. There are a few that don't work for 2 days each week, and those days will also vary. I need the formula to ignore these days as it would the weekends but in addition to the weekends. I hope that makes sense.

    I've also included a little matrix within the example that illustrates this. I have tried using this matrix to assist with the formula, but I'm failing.

    I'm hoping someone may be able to help with a standard formula I can use without tailoring it for each person.

    Many thanks

    Steve
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Formula to Calculate Occurrences of Staff Absence

    Your use of interior coloring of the cells to show non-working days means that you can only use VBA: Here is a version with a working function that will do what you want.

    Absence Tracking.xlsm

    The VBA code is used like

    =SickPeriods($B$1:$AF$1,B3:AF3)

    And here is the code for the function:

    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 05-01-2015 at 12:18 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    09-10-2014
    Location
    Hertfordshire, England
    MS-Off Ver
    2010
    Posts
    14

    Re: Formula to Calculate Occurrences of Staff Absence

    Bernie,

    Thank you so much for the response.

    I knew I perhaps wouldn't make things clear in my original posting. It's not actually the Non-Working periods I need to colour code. I only put these in yellow as a visual aid to show the Non-Working dates that should be ignored when calculating consecutive "sick" days.

    The formula I'm trying to improve on is in far right column of the spreadsheet in Column AG. I've simply highlighted this in green to make it clear.

    I'm far from being adept at VBA, but despite having said the above, your code has inspired me to include this in the spreadsheets I'm working on. Could this be adapted to take the Non-Working days from the small matrix in in B18:N20 for each person. This is the key which shows what days people work each week and is kept in a separate worksheet in my spreadsheets. The top grid is part of the monthly view which managers use.

    Many thanks again.

    Steve

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Formula to Calculate Occurrences of Staff Absence

    It's easy to change the VBA to what you need. Based on your example workbook, change the function usage to

    =SickPeriods($B$1:$AF$1,B3:AF3,E18:I18)

    and the function definition to this, which relies on the names being in the same order. We could change it to find the name in the table if that is an issue, but your sheet had the names in the same order so I was expecting that to stay the case.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-10-2014
    Location
    Hertfordshire, England
    MS-Off Ver
    2010
    Posts
    14

    Re: Formula to Calculate Occurrences of Staff Absence

    Hello Bernie,

    This is looking really good now! Thank you. I've tested it on various combinations of Non-Working Days and most of them are coming out exactly as I expect. Just a couple of anomalies I can't figure out.

    Just one thing I noticed. If someone has no days sick, the occurrence (or SickPeriod) always returns 1 instead of 0.

    I've tried a couple of changes to the code, but as I said, I'm really not confident enough with VBA, and I can't get it to correct this. I don't know whether the SickPeriods variable initially defaults to 1 somewhere, or it's to do with the boolean logic on the first pass.

    And, as if I haven't asked you enough ... going back to the original point, is there a way I can also use this VBA to highlight the cells in colour in the main view (for an instant guide to the managers rather than them having to look at the table each time - which I keep in a separate worksheet) but still allow input of hours?

    I appreciate all your time and obvious genius on this one Bernie. I'm am so much closer to getting this working than I was a few days ago thanks to you.

    Kindest reagrds
    Steve

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Formula to Calculate Occurrences of Staff Absence

    Steve,

    With my latest code, I get 0 and not 1 when I fill in a row so there is no sick time. It might be that you have a blank in the dates row or you have extended the ranges improperly so that they are too big or don't match. But it is hard to figure out without your working file.

    As for the yellow, you can use CF with the custom function option. Select from B3 to the end of your time entry area (B3 to AF5 in your sample file) and use Conditional Formatting / New Rule / "Use a formula to determine which cells to format"

    And use the formula

    =AND(WEEKDAY(B$1,2)<6,VLOOKUP($A3,$B$16:$I$20,WEEKDAY(B$1,2)+3,FALSE)="NWD")

    Where $B$16:$I$20 is the table of "Contracted Monthly & Daily Hours"

    Then set the fill format to the color you want, and you're done.

  7. #7
    Registered User
    Join Date
    09-10-2014
    Location
    Hertfordshire, England
    MS-Off Ver
    2010
    Posts
    14

    Re: Formula to Calculate Occurrences of Staff Absence

    Hi Bernie

    I've checked all those things, but still can't see anything. I must be missing something!

    I've re-attached the sample sample sheet. The only difference on my main spreadsheet is that I have zeroes instead of blanks, but I've adjusted that, and it works the same, apart from the 1 for No Sickness.

    Would you be kind enough to have a look and tell me what's clearly staring me in the face.

    And thank you for the CF advice. I tried that previously, but didn't quite get it right. I'll try yours.

    Many thanks again

    Steve
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Formula to Calculate Occurrences of Staff Absence

    Absence Tracking problem.xlsm

    I get exactly what I expect..... and this has the CF added.

    But if you want to use 0 instead of blank, then change the code to

    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 05-06-2015 at 10:36 AM.

  9. #9
    Registered User
    Join Date
    09-10-2014
    Location
    Hertfordshire, England
    MS-Off Ver
    2010
    Posts
    14

    Re: Formula to Calculate Occurrences of Staff Absence

    Hi Bernie,

    I think I see where the anomaly might be.

    In my very basic example, If there's a number in there, it means they were off sick that day for 7.4 hours, rather than the other way around.

    So, as I was poorly experimenting with earlier, do I just need to switch the boolean round to determine which is True or False to reflect this?

    And your CF example works beautifully, even in my main files with 300 staff in it. Thank you so much!

    Steve

  10. #10
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Formula to Calculate Occurrences of Staff Absence

    That does make a difference

    Try it with this code:

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    09-10-2014
    Location
    Hertfordshire, England
    MS-Off Ver
    2010
    Posts
    14

    Re: Formula to Calculate Occurrences of Staff Absence

    Bernie,

    That's so much better!! Although it seems to have thrown Duncans' count from 3 to 5 Sickperiods.

    But listen, I've taken up more than enough of your time, and you've given me so much more than I originally asked, so I'll go away and see if I can figure this last tiny piece of the puzzle out. As you say, it's no doubt something I,ve done wrong.

    I know this sort of stuff is probably standard routine to you, but I can't adequately tell you how grateful I am for both your patience and jaw-dropping (to me!) knowledge that makes this Forum and its Excel Expeerts so wonderful.

    Thank you so much Bernie!

    With the kindest regards

    Steve

  12. #12
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Formula to Calculate Occurrences of Staff Absence

    I needed to account for NWD when resetting the flag - I think this will do it:

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    09-10-2014
    Location
    Hertfordshire, England
    MS-Off Ver
    2010
    Posts
    14

    Re: Formula to Calculate Occurrences of Staff Absence

    Bernie,

    PERFECT!! Absolutely spot on across the board.

    You are outstanding. I don't think I would have spotted that, so you've saved me!

    Again, thank you so much. You've inspired me to stop being nervous about VBA.

    Steve

  14. #14
    Registered User
    Join Date
    07-23-2020
    Location
    wigan
    MS-Off Ver
    365
    Posts
    8
    Hello, i have the exact same problem. Where in column A i have a list of agent names, column d onwards are days of the year.if an agent is reported as S and then followed my a day off then S. I need the day off to auto amend to S

  15. #15
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Formula to Calculate Occurrences of Staff Absence

    Quote Originally Posted by i.boothman26 View Post
    Hello, i have the exact same problem. Where in column A i have a list of agent names, column d onwards are days of the year.if an agent is reported as S and then followed my a day off then S. I need the day off to auto amend to S
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Big number of Staff - problem of replacement / absence
    By youssefoudra in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 09-26-2014, 10:44 AM
  2. [SOLVED] Formula to Calculate Working Days and Weekends for Individual Staff
    By jlo33 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-12-2013, 12:37 PM
  3. workforce schedule / formula to calculate staff numbers at times throughout the day
    By jamesclinton82 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 04-23-2013, 08:00 PM
  4. [SOLVED] Staff Absence Record
    By Janeong in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-27-2012, 08:56 AM
  5. formula to calculate staff performance
    By daveyy in forum Excel General
    Replies: 6
    Last Post: 11-07-2008, 07:52 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1