• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1293
  • Last Modified:

Loan Laptop Database Using Excel 2007 - Identify late laptops and persistant offenders

Ive created a Loan Laptop spreadsheet in Excel that shows basically
who loaned the laptop
the from date
the to date
and if it has been returned
.

I created formula that shows clearly when an item is overdue and has not been returned but.....

Is their a way so that if an item is overdue it adds that users name to another sheet and includes the number of days over due and the number of times its has been overdue from that user.

e.g. Fred has borrowed a laptop for 7 days, its now day 10 and it hasnt been returned. He has  done this before but i cant see how many times. Id like the sheet to show that he has not returned the laptop X times to a total of X number of days. Built-PCs---Loan-Laptops.xlsx
0
Duco_IT
Asked:
Duco_IT
  • 3
1 Solution
 
als315Commented:
Look to pivot table in sheet1. You will need additional fields and you fields should be filled with date values.
Built-PCs---Loan-Laptops.xlsx
0
 
patrickabCommented:
Duco_IT,

As you are not recording when a laptop is returned it is not possible to analyse whether they were early, on time or late. At the very least you need a column to record the date on which a laptop is returned.

In fact the 'Returned' column should be used for that rather than recording only whether or not it has been returned. If there's a blank in the Returned column then by implication, the laptop has not been returned. If it has been returned then a date of return is needed.

Patrick
0
 
patrickabCommented:
Duco_IT,

In the 'Returned' column in the attached file I have inserted random dates to simulate the dates the laptops were returned.

The code below, also in the attached file produces a report giving you a picture of User's returns' records. Press the button on the Report sheet to obtain the results.

Hope it helps

Patrick
Sub specialmacro()
Dim rng As Range
Dim rng2 As Range
Dim celle As Range
Dim celle2 As Range
Dim coll As New Collection
Dim i As Long
Dim xborrowed As Long
Dim xontime As Long
Dim xlate As Long
Dim dayslate As Long

With Sheets("Loan Laptops")
    Set rng = Range(.Cells(2, "B"), .Cells(.Rows.Count, "B").End(xlUp))
End With

For Each celle In rng
    If celle.Value > 0 Then
        On Error Resume Next
        coll.Add CStr(celle), CStr(celle)
    End If
Next celle

With Sheets("Report")
    .Cells.ClearContents
    For i = 1 To coll.Count
        .Cells(i + 1, "A") = coll(i)
    Next i
    .Cells(1, "A") = "User"
    .Cells(1, "B") = "Times borrowed"
    .Cells(1, "C") = "Returned on-time"
    .Cells(1, "D") = "Returned late"
    .Cells(1, "E") = "Total days late"
    .Cells(1, "F") = "Ave. days late"
    .Rows(1).Font.Bold = True
    .Columns("A:F").AutoFit
    Set rng2 = Range(.Cells(2, "A"), .Cells(.Rows.Count, "A").End(xlUp))
End With

For Each celle2 In rng2
    For Each celle In rng
        If celle2 = celle Then
            xborrowed = xborrowed + 1
            If celle.Offset(0, 3) <= celle.Offset(0, 2) Then
                xontime = xontime + 1
            Else
                xlate = xlate + 1
                dayslate = dayslate + (celle.Offset(0, 3) - celle.Offset(0, 2))
            End If
        End If
    Next celle
    celle2.Offset(0, 1) = xborrowed
    celle2.Offset(0, 2) = xontime
    celle2.Offset(0, 3) = xlate
    celle2.Offset(0, 4) = dayslate
    celle2.Offset(0, 5) = IIf(dayslate = 0, 0, Int(dayslate / xlate))
    xborrowed = 0
    xontime = 0
    xlate = 0
    dayslate = 0
Next celle2

End Sub

Open in new window

Loan-laptops-01.xls
0
 
Duco_ITAuthor Commented:
Thanks loads for that
0
 
patrickabCommented:
Duco_IT - Pleased it helped. Thanks for the grade. - Patrick
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now