Solved

Show missed days since last login, if not today

Posted on 2015-01-11
5
72 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 78

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now