Thread: Dates
View Single Post
  #6  
Old May 16th, 2007, 12:22 AM posted to microsoft.public.excel.misc
Dave Peterson
external usenet poster
 
Posts: 19,791
Default Dates

Another version:

Option Explicit
Function DaysWorked(StartDate As Date, EndDate As Date) As String

Dim myDate As Date
Dim myStr As String

myStr = ""
For myDate = StartDate To EndDate
If (Weekday(myDate) = vbMonday) _
And (Weekday(myDate) = vbFriday) Then
myStr = myStr & "," & Format(myDate, "m/d")
End If
Next myDate

If myStr "" Then
myStr = Mid(myStr, 2)
End If

DaysWorked = myStr

End Function




Scafidel wrote:

Hey, thanks alot Joel. I guess I need to learn more about VB, I keep finding
solutions there. For some reason, I am getting a space after the slash, 5/
1, 5/ 2. Otherwise it works great.
Thanks
Scafidel
Louisiana

"Joel" wrote:

try this custom function
If A1 has 5/1/07 and b1 has 5/15
=daysworked(A1,B1)

or just
=daysworked(5/1/07,5/15/07)






Function daysworked(startdate as date, enddate as date) As String
Dim mydate As Date

daysworked = ""
For mydate = startdate To enddate

If (Weekday(mydate) = vbMonday) And _
(Weekday(mydate) = vbFriday) Then

If daysworked "" Then daysworked = daysworked + ","
a = Month(mydate)
b = Day(mydate)
daysworked = daysworked + Str(Month(mydate)) + "/" + Str(Day(mydate))

End If

Next mydate

End Function


"Scafidel" wrote:

I have an invoice with a starting date through ending date of workdays. I
use NETWORKDAYS to find the total, but I would also like to list the dates
worked in one cell, like C1, below. similar to this. What formula should I
use?
A1 B1 C1
5/01/07 5/15/07 5/1,5/2,5/3,5/4,5/7,etc

Thanks
Scafidel
Louisiana


--

Dave Peterson