Total all occurences of value in a range

Human_doing

Board Regular
Joined
Feb 16, 2011
Messages
137
Hi all,

The below code provides the number of cells where the contained date falls within two date ranges and loops this process across every worksheet in a workbook.

Can anyone please provide the code to total the instances of an exact match rather than between two dates, i.e. the number of times that the word 'excel' comes up in a range?

Thanks

Code:
Sub Looper()
'Total the number of occurences using formula
Dim Sh As Worksheet
Dim LR As Long
For Each Sh In ActiveWorkbook.Worksheets
With Sh
LR = .Range("E" & .Rows.Count).End(xlUp).Row
 
.Range("I2").Formula = "=SUMPRODUCT((E2:E" & LR & ">MonthSheet!B2)*(E2:E" & LR & "<MONTHSHEET!C2))"< p>  
End With
 
Next Sh
 
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi, yes perhaps COUNTIF would be better for this however the SUMPRODUCT has got the job done for the first part of what I needed, I'm not sure which would be best for this?

Thanks
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,848
Members
452,948
Latest member
UsmanAli786

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