Hi! I am a mostly-self-taught VBA novice. I am trying to create a VBA formula that will go through my previously sorted data and count only the visible cells with a date within two years of the current date.
So far, here is where I am stuck:
Sub CountIF()
'
' CountIF Macro
'
With Sheets("Loans by Maturity")
Dim MyDate As Long
MyDate = (Date + (365 * 2))
Dim x As Long
x = Range("R" & Rows.Count).End(xlUp).Row
If x <= (Date + (365 * 2)) Then
Range("C2") = WorksheetFunction.CountIF(x And (Cells.SpecialCells(xlTypeVisible)), "<=" & MyDate)
'This is where my error lies, I believe
End If
End With
End Sub
Thank you so much for your help!!!
So far, here is where I am stuck:
Sub CountIF()
'
' CountIF Macro
'
With Sheets("Loans by Maturity")
Dim MyDate As Long
MyDate = (Date + (365 * 2))
Dim x As Long
x = Range("R" & Rows.Count).End(xlUp).Row
If x <= (Date + (365 * 2)) Then
Range("C2") = WorksheetFunction.CountIF(x And (Cells.SpecialCells(xlTypeVisible)), "<=" & MyDate)
'This is where my error lies, I believe
End If
End With
End Sub
Thank you so much for your help!!!