Find 1st Friday in January

DanG

Registered User.
Local time
Today, 15:26
Joined
Nov 4, 2004
Messages
477
Sorry so many questions, but I'm on a project and fairly new to excel...

I am trying to find the first friday in january of any given year (so I don't have to change my starting date every year manually).

In the end I want to list every friday of the year down the column. Once I have the first friday it's easy enough, just not sure how to get it.

Thank you
 
i did something like this a while back. I have to admit the function code is not mine but I have no idea where I got it from, it was a while ago.

Code:
Sub FindFridays()

Dim x As Integer


ThisWorkbook.Worksheets("sheet1").Range("a1") = ndm("FRI", "01/01/2007", 1)

x = 2

For x = 2 To 52 Step 1
    
    ThisWorkbook.Worksheets("sheet1").Cells(x, 1) = (x * 7) + ThisWorkbook.Worksheets("sheet1").Range("A1").Value

Next x

    

End Sub




Function ndm(Which_Day As String, Which_Date As String, Occurence As Byte) As Date
Dim i As Integer
Dim iDay As Integer
Dim iDaysInMonth As Integer
Dim FullDateNew As Date
Dim lCount As Long

Which_Date = CDate(Which_Date)
 
        Select Case UCase(Which_Day)
            Case "SUN"
                iDay = 1
            Case "MON"
                iDay = 2
            Case "TUE"
                iDay = 3
            Case "WED"
                iDay = 4
            Case "THU"
                iDay = 5
            Case "FRI"
                iDay = 6
            Case "SAT"
                iDay = 7
            End Select
 
      
    FullDateNew = DateSerial(Year(Which_Date), Month(Which_Date), 1)
   
    iDaysInMonth = Day(DateAdd("d", -1, DateSerial _
        (Year(Which_Date), Month(Which_Date) + 1, 1)))

    For i = 0 To iDaysInMonth
        If Weekday(FullDateNew + i) = iDay Then
            lCount = lCount + 1
        End If
        If lCount = Occurence Then
            ndm = FullDateNew + i
            Exit For
        End If
    Next i

End Function
 
Thank you, I'll give it a try.

On the surface it seem's like it should be easy, but getting deeper into it...not so much.
 

Users who are viewing this thread

Back
Top Bottom