This should work, I've checked it with a few random dates. If you've got any problems, just repost.
Public Sub Main()
Dim MyFriday As Date
Dim MyDate As Date
MyDate = #1/2/2002#
MyFriday = NextFriday(MyDate)
MsgBox MyFriday
End Sub
Private Function NextFriday(MyDate As Date) As Date
Dim MyDay As Integer
MyDay = Weekday(MyDate, vbSunday)
Delta = vbFriday - MyDay
NextFriday = MyDate + Delta
End Function
Use this UDF.
Function Friday(DateRange As Date) As Date
Friday = DateRange + 7 - WeekDay(DateRange, 7)
End Function
You can use it directly in Excel. Assuming your sample data is in A1:A5, put this formula in B1
=Friday(A1)
and drag down.
Juan Pablo G.
Nicer tidier version of what I suggested. Damn you JPG. :)
I was just seeing what you suggested. I forgot about vbFriday, and can you believe that the Excel function Weekday doesn't accept 7 as a second argument ????? only 0, 1 or 2 !!!
Incredible, same function, works different in VBA and in Excel.
Juan Pablo G.
I thought that 7 was a bit suspicious, especially as it's not been ten minutes since I was looking in Excel help to see why the "Day" function wasn't doing what I wanted. Then I remembered "Weekday". duh. Oh well.
I appreciate your solutions. Not one, but two or three ways to skin a cat. Ooouueee, that's gross!
That solved my problem!