problem with CountIf VBA (getting 'unable to get the CountIf property' error...)

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
476
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I need the code to look at visible cells (ones that have not been filtered) cells in column 'T' starting at row 31 and down to where I know there is no more data... I'm using '2000' just to to make sure that its looking all the way down to the bottom.

Within this range, I want the CountIf to count the number of times that it finds the string "RMA" and then put that number in cell T28.

Here is my code:
Code:
ActiveWorkbook.Worksheets("MTHLY_REPORTS").Range("T28").value = Application.WorksheetFunction.CountIf(Range("T31:T2000").SpecialCells(xlCellTypeVisible), "RMA")

I'm getting the error: Run-time error '1004' Unable to get the CountIf property of the WorksheetFunction class.

Red is cell T28 where I want the CountIf value to appear, and blue is the target string ("RMA") that I want the CountIf to find and count. (it should be a '1' that is placed into T28.)
CountIf_RMA.JPG

Thanks for any help or suggestions!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
CounIf does not accept a multi-area range. A possible workaround would be:
VBA Code:
Dim count AS Long, r As Range
For Each r In Range("T31:T2000").SpecialCells(xlCellTypeVisible).Areas
    count = count + WorksheetFunction.CountIf(r, "RMA")
Next
ActiveWorkbook.Worksheets("MTHLY_REPORTS").Range("T28").Value = count
 
Upvote 0
Solution
CounIf does not accept a multi-area range. A possible workaround would be:
VBA Code:
Dim count AS Long, r As Range
For Each r In Range("T31:T2000").SpecialCells(xlCellTypeVisible).Areas
    count = count + WorksheetFunction.CountIf(r, "RMA")
Next
ActiveWorkbook.Worksheets("MTHLY_REPORTS").Range("T28").Value = count

Excellent. That works perfectly. Thank you, Flashbond
 
Upvote 0

Forum statistics

Threads
1,223,521
Messages
6,172,813
Members
452,481
Latest member
Najwan

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