VBA COUNTIF with Visible Cells, count conditions, current date

BeccaBKD

New Member
Joined
Feb 24, 2016
Messages
5
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!!!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,223,604
Messages
6,173,320
Members
452,510
Latest member
RCan29

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top