usage of WorksheetFunction.Year in excel vba For loop

acr

I have a series of dates in my sheet DailyData A column. I need to find out whether its leap year (in A Column) and depends upon that performing a calculation in F Column.( for leap year, I need to use 366 else 365)

Found that using below formula, I can check its leap year or not.

b = 4 a=Year to check

``````If a - (b * (a \ b)) = 0, then its leap year
``````

Now, I am using below code to perform the calculation, but its giving me error `"Object doesn't support this property or method"` on line `a = WorksheetFunction.Year("A", J)`

What will be correct method of check it ?

``````Sub DayTest()
Dim MaxGain As Workbook
Dim Main As Worksheet
Dim DailyData As Worksheet
Dim n As Long
Dim J As Long
Dim a As String, b As Integer

Set MaxGain = Excel.Workbooks("MaxGain.xlsm")
Set DailyData = MaxGain.Worksheets("DailyData")
Set Main = MaxGain.Worksheets("Main")
DailyData.Activate

n = DailyData.Cells(Rows.Count, "A").End(xlUp).Row

J = 1
b = 4

For J = 2 To n

a = WorksheetFunction.Year("A", J)

If a - (b * (a \ b)) = 0 Then

DailyData.Range("F" & J).Value = Main.Range("B2").Value / 366

Else

DailyData.Range("F" & J).Value = Main.Range("B2").Value / 365

End If

Next

End Sub
``````

UPDATE: I have figured it. Changed the line

``````a = WorksheetFunction.Year("A", J)
``````

to

``````a = Year(DailyData.Range("A" & J))
``````
acr

I have figured it.Changed below line

``````a = WorksheetFunction.Year("A", J)
``````

to

``````a = Year(DailyData.Range("A" & J))
``````

Collected from the Internet

edited at

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev

From Dev