Count instances of text on a different worksheet

raeannb

Board Regular
Joined
Jun 21, 2011
Messages
86
Hello! My problem may possibly (??) be solved with a CountIf function or similar, but I'm trying and failing miserably. Here it is:

I have two worksheets set up, one called "Sites" and the other called "IDs." On "Sites" is a column of 5-digit numerical (but formatted as text) site IDs, and on "IDs" is a range containing 9-digit customer IDs of the format #####-###, where the first five digits correspond to a site ID. What I would like to do is loop through column A of "Sites" (which contains the Site IDs) and have my program count the number of times a customer from each site occurs in the given range on "IDs." I then would like the count to be placed alongside the site number on "Sites" in column B.

So far I have:


Sub CountSites()
With Worksheets("Sites")
x = .Range("A65536").End(xlUp).Row - 5
For i = 1 To x
.Range("B" & i + 5).Value = .CountIf(Worksheets("IDs").Range("B6:P36") _
, Worksheets("Sites").Range("A" & i + 5).Value) **** ERROR
Next i
End With
End Sub

I'm getting an "Object doesn't support this property or method" error at the CountIf function. Any clue what I'm doing wrong?

Thank you!!!!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I figured it out! For anyone who wants to know, I gave up on VB and just put this formula in column B:


=SUMPRODUCT((LEFT('IDs'!$A$6:$P$38, 5)= A6)+0)

Ta da! Happy counting, everyone...
 
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,476
Members
452,915
Latest member
hannnahheileen

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