CountIf Usage Across Two Worksheets

Tuffman

New Member
Joined
May 31, 2012
Messages
49
Office Version
  1. 2016
Platform
  1. Windows
I can't get this code to run, I keep getting an error that says "Compile error: Invalid qualifier". I'm wanting to count the number of blue cars on the "Cars" worksheet in column J from rows 45-70. Then have that number shown in cell C10 on the Summary worksheet. Can someone help me understand why this isn't running?


Worksheets("Summary").Range("C10") = Worksheets("Cars").WorksheetFunction.CountIf(Range("J45:J70"), "Blue")
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Your sheet reference needs to go before the range reference, i.e.
VBA Code:
    Worksheets("Summary").Range("C10") = WorksheetFunction.CountIf(Worksheets("Cars").Range("J45:J70"), "Blue")
 
Upvote 0
Solution
Your sheet reference needs to go before the range reference, i.e.
VBA Code:
    Worksheets("Summary").Range("C10") = WorksheetFunction.CountIf(Worksheets("Cars").Range("J45:J70"), "Blue")
Thank you Joe4, that worked perfectly!
 
Upvote 0
You are welcome.

Please note: When marking a post as the solution, please mark the original post containing the solution (and not your own post indicated that another post is the solution).
I have updated this one for you.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

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