# Thread: COUNTIF "H" and "h" (2000/2002)

1. ## COUNTIF "H" and "h" (2000/2002)

I'm trying to create a simple function that will add the occurances of the single letter "H" in a column:<pre>=(COUNTIF(J6:J42,"H"))</pre>

Unfortunately (for me), the function is including occurrances of the lowercase - "h".
(The ultimate aim is to get a function that will give me the sum of the number of H's and h's, where "H" = 1 and "h" = 0.5.)
Could someone please nudge me in the right direction?

2. ## Re: COUNTIF "H" and "h" (2000/2002)

This user defined function should give you what you want:

<pre>Public Function GetCount(oVals As Range, strChr As String) As Long
Dim lCount As Long, oCell As Range
lCount = 0
For Each oCell In oVals
If oCell.Value = strChr Then
lCount = lCount + 1
End If
Next oCell
GetCount = lCount
End Function
</pre>

In the sheet use:

=GetCount(J6:J42,"H")

3. ## Re: COUNTIF "H" and "h" (2000/2002)

Hi Leif,
Just as an alternative to Legare's function, you could use:
=SUM(IF(EXACT(J6:J42,"h"),1,0))
array-entered.
FWIW.

4. ## Re: COUNTIF "H" and "h" (2000/2002)

Perfect!
Many thanks to you both. I got Legare's solution up and running first, so I'm quitting while I'm ahead. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•