I am trying to count the number of times a sub-string appears within a column of string data in Excel. Please see the below example.
The column of string data (tweets) looks like this:
A 1 An example string with @username in it 2 RT @AwesomeUser says @username is awesome
The column with "substrings" (Twitter screen names) looks like this:
B 1 username 2 AwesomeUser
I want to use a formula to count the number of times that a substring from B1, B2, etc. appears in the strings in column A. For example: a formula searching for B1 would return "2" and a search for B2 would return "1".
I can't do it this way:
=COUNTIF(A:A, "username")
because COUNTIF only looks for strings, not substrings. This formula would always return "0".
Here's a formula I thought might do it:
=SUMPRODUCT((LEN(A:A)-(LEN(SUBSTITUTE(A:A,"username",""))))/LEN("username"))
Unfortunately, I have 16,000 entries in column B and tens of thousands in A, so counting characters won't work even on a high power PC (also, the result returned by the function is suspect).
I thought about using:
=COUNTIF(A:A, "*username*")
but COUNTIF requires a string with the star operators; I need to use cell references due to the volume of data.
My question: does anyone know how I can use a formula for this? If using COUNTIF, how do I get a cell reference in the conditional part of the statement (or use a function to substitute the string in the cell referenced within the conditional part of a COUNTIF statement)?
I know that I could parse the data, but I would like to know how to do it in Excel.
Select a blank cell you will place the counting result at, type the formula =COUNTIF(A1:A16,"*Anne*") (A1:A16 is the range you will count cells, and Anne is the certain partial string) into it, and press the Enter key. And then it counts out the total number of cells containing the partial string.
This is one of the most straightforward formulas to count characters in Excel. The LEN function calculates the string length for each cell in the specified range and returns them as an array of numbers. And then, SUMPRODUCT or SUM adds up those numbers and returns the total character count.
Count number of occurrences in a date range with formulas Select a blank cell that you want to place the count result, and enter this formula =SUMPRODUCT((A2:A14>=$D$1)*(A2:A14<=$D$2)), press Enter key. Now the number of occurrence in date range has been counted.
The string count() method returns the number of occurrences of a substring in the given string. In simple words, count() method searches the substring in the given string and returns how many times the substring is present in it.
You are nearly there, use
=COUNTIF(A:A, "*"&B1&"*")
Caveat:
This counts the number of cells in A:A
that contain the string one or more times. It does not count the total number of instances of the string.
A very Simple Excel Solution for occurrence of x-string ("ABC") into y-string ("ABC 123 ABC 23dfABC"):
Number of Occurrence: len(substitute(y,x,x1)) - len(y)
Nomenclature for Understanding: x-string: "ABC" x1-string: "ABC_" y-string: "ABC 123 ABC 23dfABC" y1-string: ""ABC_ 123 ABC_ 23dfABC_"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With