Solved

Show missed days since last login, if not today

Posted on 2015-01-11
5
75 Views
Last Modified: 2015-01-18
With this v3 posted here http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_28591073.html, we are not taking into account missed days if there is no new login information.  

I have one record where the person's last day to login was 1/1 but the report should show the missed days, so long as it isn't today.
0
Comment
Question by:frugalmule
  • 3
5 Comments
 
LVL 12

Assisted Solution

by:FarWest
FarWest earned 375 total points
ID: 40543161
Check this  MissedDays replacement

the idea is to replace the cells(I,"G") reference with a variable, that will be today if working in the last row

I hope this would help

 
Sub MissedDays()
Dim WS As Worksheet
Dim tMissedHours As Date
Dim MaxRow As Long, I As Long, lMissedDays As Long
Dim LastDay As Date
Dim ThisDay As Date
Dim DaysOff As String, sMissedDays As String
Dim vMissedDays, J
Dim dStart As Date, dEnd As Date
Dim bMissed As Boolean

'---> Set Variables
Set WS = ActiveSheet
MaxRow = WS.Range("A" & WS.Rows.Count).End(xlUp).Row
LastDay = WS.Range("G3")
bMissed = False

For I = 0 To Worksheets("Main").ListBox1.ListCount - 1
    If Worksheets("Main").ListBox1.Selected(I) Then
        If DaysOff <> "" Then DaysOff = DaysOff & ", "
        DaysOff = DaysOff & Worksheets("Main").ListBox1.List(I, 0)
    End If
Next I

'---> Start Calculations
For I = 3 To MaxRow
    ThisDay = WS.Cells(I, "G")
    If I = MaxRow Then
    ThisDay = Date
    End If
    If ThisDay <> LastDay And Not bMissed Then
        lMissedDays = DateDiff("d", LastDay, ThisDay) - 1
        If lMissedDays > 0 Then
            sMissedDays = ""
            vMissedDays = vbEmpty
            dStart = DateAdd("d", 1, LastDay)
            dEnd = DateAdd("d", -1, ThisDay)
            For J = dStart To dEnd
                If InStr(1, DaysOff, Weekday(J)) = 0 And Format(J, "mm/dd") <> "12/25" Then
                    '---> Record that day as Missed day
                    If sMissedDays <> "" Then sMissedDays = sMissedDays & "; "
                    sMissedDays = sMissedDays & J
                    bMissed = True
                End If
            Next J
            
            If bMissed Then
                vMissedDays = Split(sMissedDays, ";")
                WS.Cells(I, "P") = Trim(vMissedDays(LBound(vMissedDays)))
                WS.Cells(I, "Q") = Trim(vMissedDays(UBound(vMissedDays)))
                WS.Cells(I, "R") = UBound(vMissedDays) + 1
                WS.Cells(I, "S") = WS.Cells(I, "R") * (TimeValue(tShiftEnd) - TimeValue(tShiftStart))
                WS.Cells(I, "S").NumberFormat = "[h]:mm;@"
                bMissed = False
            End If
        End If
        
        '---> Update Last Day
        LastDay = ThisDay
        
    End If

Next I
End Sub

Open in new window

0
 

Author Comment

by:frugalmule
ID: 40543246
can you attach the integrated file?
0
 
LVL 12

Assisted Solution

by:FarWest
FarWest earned 375 total points
ID: 40543334
I am far from computer now
but you just open the code and repace the sub with this new one
ps. you should have developr bar, by customizing the ribbon and add it
0
 
LVL 80

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 125 total points
ID: 40548073
0
 
LVL 12

Accepted Solution

by:
FarWest earned 375 total points
ID: 40548502
Here is updated version 4 of the file,
TimeCalc-V04.xlsm
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question