Solved

Show missed days since last login, if not today

Posted on 2015-01-11
5
78 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 81

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

734 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