LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default traveling days

By my reckoning, your example has 12 days, not 11. The days worked by any
employee are

Jan-1, 2, 3, 4, 5, 6, 20, 21, 22, 23, 24, 25

You can use the following VBA function to calculate company days. DateRange
is a 2 column range containing the start and end dates for each employee,
with the start date in the first column and the end date in the second
column. The IgnoreWeekends parameter indicates whether to exclude weekend
days (Saturday and Sunday) from the count. If this parameter is True or
omitted, weekends are not counted. If this parameter is False, weekend days
are included in the count.

If an invalid date is encountered, the function returns a #VALUE error.

Function CompanyDays(DateRange As Range, _
Optional IgnoreWeekEnds As Boolean = True) As Variant
Dim FirstDate As Long
Dim LastDate As Long
Dim RR As Range
Dim N As Long
Dim Arr() As Long

On Error Resume Next
With Application.WorksheetFunction
Err.Clear
FirstDate = .Min(DateRange.Columns(1))
If Err.Number < 0 Then
CompanyDays = CVErr(xlErrValue)
Exit Function
End If

LastDate = .Max(DateRange.Columns(2))
If Err.Number < 0 Then
CompanyDays = CVErr(xlErrValue)
Exit Function
End If

If LastDate < FirstDate Then
CompanyDays = CVErr(xlErrValue)
Exit Function
End If

Err.Clear
ReDim Arr(FirstDate To LastDate)
If Err.Number < 0 Then
CompanyDays = CVErr(xlErrValue)
Exit Function
End If
For Each RR In DateRange.Columns(1).Cells
For N = CLng(RR.Value) To CLng(RR(1, 2).Value)
If IgnoreWeekEnds = True Then
If Weekday(N, vbMonday) <= 5 Then
Arr(N) = 1
End If
Else
Arr(N) = 1
End If
Next N

Next RR
CompanyDays = .Sum(Arr)
End With

End Function


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)


wrote in message
...
I have raw data in Excel, but need to calculate total number of
company days of time spent on certain projects. For example I have 3
employess who spend the following days on the following project.

Employees Days Working Individual Time on Project
Emp. 1 1/1/2007-1/5/2007 5 days
Emp. 2 1/2/2007-1/6/2007 5 days
Emp. 3 1/20-2007-1/25/2007 5 days

Total Company Time on
Project 11 days

The total is 11 days of company time on the project because of the
overlapping days on Emp. 1 and Emp. 2. I have the days working of
these employees, but need to calculate that raw data into total
company days spent on each project. Any assistance is appreciated.


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to pull <=14 Days, <=30 Days, 30 Days from a date column Ken Excel Discussion (Misc queries) 3 October 23rd 09 12:53 AM
Employee days worked (-Holidays, -weekends, Snow Days, etc) Denise Excel Discussion (Misc queries) 2 December 31st 08 04:37 PM
Calc days between two dates and exclude leap year days scoz Excel Worksheet Functions 5 November 23rd 07 03:58 PM
Conditional Formatting Dates calculating 10 days and 30 days from a certain date Sioux[_2_] Excel Worksheet Functions 2 October 11th 07 02:04 PM
Is there a template for a number of people traveling by month? CP Excel Discussion (Misc queries) 0 December 13th 04 05:31 PM


All times are GMT +1. The time now is 03:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"