Formula to count multiple instances of a string in a cell in a range

KlayontKress

Board Regular
Joined
Jan 20, 2016
Messages
67
Office Version
  1. 2016
Platform
  1. Windows
To all,


I am looking for a way to count multiple instances of a particular string in a cell over a range. I have found a way to count if a single string of characters is in a cell in a range but I'm having trouble counting multiple instances of the same string in a single cell in a range. I found a formula to count multiple instances in a single cell only, but this would require a formula next to each entry in the column to parse this data and then summing those values up. this isn't necessarily a deal breaker if I had just a few strings to look up but I will have several dozen strings to parse and having tens or hundreds of thousands of formulas trying to calculate this would be taxing on excel. I will have thousands of lines of data in the end sheet that is tied to a refresh-able report tied to a data cube.

What I'm trying to do is query results from an audit in which the auditor uses specific codes: 1A, 2A, 3A, Etc. to denote that a particular issue has been found. The data is coming from proprietary software that has "tasks" that get created for an audit, are assigned to a particular individual, and allow for the auditor to put information in an instructions field. I want to query these particular fields to parse that information out so that we can work on training the individuals based on their weak areas. It's possible for a task to have text in the following format: 1A2A1A3A5G6E1A2D3F. If I reorder that and space it apart to make it easier to read, it's: 1A 1A 1A 2A 2D 3A 3F 5G 6E.

What I currently have created is a table with formulas to parse out who the task is assigned to and the 1A, 2A, 3A, etc. codes. This works, but it's only finding single instances in a particular cell but it works over an entire range (I can search the entire columns the data is in). The formula will find the first instance of each string (1A, 2A, 3A, etc.) but not multiple instances of a single string such as 1A 1A 1A.The formula I use to do this is:

=COUNTIFS($Y:$Y,"*"&$A3&"*",$W:$W,B$2)

Where:
A3 is the code we want to query
B2 is the individual we want to query
Column Y has the Codes to be queried from the pivot table
Column W has the Names to be queried from the pivot table


[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD][/TD]
[TD]A
[/TD]
[TD]B
[/TD]
[TD]C
[/TD]
[TD]D
[/TD]
[TD]E
[/TD]
[TD]F
[/TD]
[TD]G
[/TD]
[TD]H
[/TD]
[TD]I
[/TD]
[TD]J
[/TD]
[TD]K
[/TD]
[TD]L
[/TD]
[TD]M
[/TD]
[TD]N
[/TD]
[TD]O
[/TD]
[TD]P
[/TD]
[TD]Q
[/TD]
[TD]R
[/TD]
[TD]S
[/TD]
[TD]T
[/TD]
[TD]U
[/TD]
[TD]V
[/TD]
[TD]W
[/TD]
[TD]X
[/TD]
[TD]Y
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]Issue Code
[/TD]
[TD]Jenny
[/TD]
[TD]Bob
[/TD]
[TD]Lauren
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]pivot table starts here
[/TD]
[TD][/TD]
[TD]Assigned To:
[/TD]
[TD][/TD]
[TD]Instructions
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]1A
[/TD]
[TD]2 (Should be 3)
[/TD]
[TD][/TD]
[TD]1
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Jenny
[/TD]
[TD][/TD]
[TD]1A 1A 1B 2A 2B
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]1B
[/TD]
[TD]1
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Lauren
[/TD]
[TD][/TD]
[TD]1A 2A
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]1C
[/TD]
[TD][/TD]
[TD][/TD]
[TD][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can use =((LEN(Y2)-LEN(SUBSTITUTE(Y2,$A$2,"")))/LEN($A$2)) to count the multiples in Y2 but I have to have this next to each cell in the Y column and then sum it up. I then need this formula for each code to look up requiring multiple columns of thousands of formulas each to get this information. This requires a lot of time to calculate every time a change is made in excel. Is there a way to adapt this code to look at multiple instances in a particular cell over an entire range?

Any help would be greatly appreciated.


Thanks in advance,
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
You can probably do that but before i have a look why do you have (should be 3)? Looks like 2 is correct to me.
 
Upvote 0
Using your example place in B2:

=SUMPRODUCT(--($W$2:$W$7=B$1),(LEN($Y$2:$Y$7)-LEN(SUBSTITUTE($Y$2:$Y$7,$A2,"")))/LEN($A2))

Drag down and across.
 
Upvote 0
Steve,


Thank you for the quick reply. when I initially started writing this reply I couldn't get your formula to work. Then I realized that there was a case difference. I inserted the necessary uppers to account for this and it works beautifully. Thank you for the solution. I didn't realize it would be that easy.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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