View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default Question using countif

This UDF can be used to count occurences of numbers or text in a range.

Function CountChar(InRange As Range, Letter As String) As Long
Dim rng As Range
For Each rng In InRange
CountChar = CountChar + Len(rng.text) - _
Len(Application.WorksheetFunction.Substitute(UCase (rng.text) _
, UCase(Letter), ""))
Next rng
End Function

=CountChar(A3:A20,"2")

A cell or range contains 26 or 2,6 or 226 or all of those.

The count will be 4


Gord Dibben MS Excel MVP

On Tue, 11 May 2010 15:43:01 -0700, Tim JA
wrote:

The formula you provided works for cells containing a single number. How can
I get it to include a specific number in cells with multiple numbers as well?
For example, if I wanted occurrences for the number 2... there's a cell with
just that number by itself and another cell that has both 2 and 6. In this
case, the formula should come up with 2 occurrences...

"Ashish Mathur" wrote:

Hi,

Actually the simplest approach would be to use text to columns to segregate
numbers in different columns and then use the countif

=countif(A3:F50,A55)
--
Regards,

Ashish Mathur
Microsoft Excel MVP
www.ashishmathur.com

"Tim JA" <Tim wrote in message
...
I'm using office 2007, specifically excel. I cannot get the countif
function
to accurately count cells containing multiple numbers. For example below
is a
column containing both single and multiple numbers. I'm trying to get a
count
based on any number in the column. Perhaps, I'm using the wrong count
function. I've tried using wild cards... but to no avail. Your help would
be
greatly appreciated.



5
9
2,6
2
3,6
6,7
5,13
2

6

1,10,13
13

.