Solved

Show missed days since last login, if not today

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

Independent Software Vendors: 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

Suggested Solutions

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…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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.

730 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