Hi,
I am trying to run a macro and I keep getting an error message.
Can anyone pinpoint where the mistake is please?
Function MonthDiff(date1 As Date, date2 As Date) As Long
MonthDiff = DateDiff(m, date1, date2)
End Function
Sub Calc_Dates_Stat2()
Dim prev_date As Date
Dim curr_date As Date
Dim Months
Dim NA As Boolean
Range("U2").Select
Do Until IsEmpty(Range("T" & ActiveCell.Row))
NA = False
If IsEmpty(Range("B" & ActiveCell.Row)) Then
NA = True
Else
curr_date = Range("B" & ActiveCell.Row).Value
End If
If IsEmpty(Range("A" & ActiveCell.Row)) Then
NA = True
Else
prev_date = Range("A" & ActiveCell.Row).Value
End If
If NA = False Then
ActiveCell.Value = MonthDiff(prev_date, curr_date)
End If
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Thanks
I am trying to run a macro and I keep getting an error message.
Can anyone pinpoint where the mistake is please?
Function MonthDiff(date1 As Date, date2 As Date) As Long
MonthDiff = DateDiff(m, date1, date2)
End Function
Sub Calc_Dates_Stat2()
Dim prev_date As Date
Dim curr_date As Date
Dim Months
Dim NA As Boolean
Range("U2").Select
Do Until IsEmpty(Range("T" & ActiveCell.Row))
NA = False
If IsEmpty(Range("B" & ActiveCell.Row)) Then
NA = True
Else
curr_date = Range("B" & ActiveCell.Row).Value
End If
If IsEmpty(Range("A" & ActiveCell.Row)) Then
NA = True
Else
prev_date = Range("A" & ActiveCell.Row).Value
End If
If NA = False Then
ActiveCell.Value = MonthDiff(prev_date, curr_date)
End If
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Thanks