Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Show missed days since last login, if not today

Posted on 2015-01-11
5
Medium Priority
?
82 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 1500 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 1500 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 84

Assisted Solution

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

Accepted Solution

by:
FarWest earned 1500 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

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!
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

963 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