COUNTIF "string" in cell

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All.......
How might the code read to perform a check of all cells in the selected
column and count all the cells which contain a certain string at least once,
and place the total in cell B1. That is, if the string exists by itself, or
within a string of other characters in the same cell.....and if multiple
times in one cell, only count once.

If looking for JOHN,
Cell with JOHN ...would count 1
Cell with JOHN/BILL /TOM & OTHERS... would count 1
Cell with JOHN / BILL,JOHN ...would count 1
Cell with BILL, TOM ...would not count
(note the inconsistant punctuation)

TIA for any help
Vaya con Dios,
Chuck, CABGx3
 
something like
mc=0
for each c in selection
if instr(c,"John")>0 then mc=mc+1
next c
msgbox mc
 
Cool, thanks JE..........just tweaked it a bit for my application...

Sub FindName()
Range("B1").Formula = "=COUNTIF(n:n,""*john*"")"
End Sub

Many thanks..........
Vaya con Dios,
Chuck, CABGx3
 
Thanks Don..........works good but seems to be "case sensitive".......can
anything be done to change that?

Vaya con Dios,
Chuck, CABGx3
 
Sub countjohn()
For Each c In Selection
If InStr(UCase(c), "JOHN") > 0 Then mc = mc + 1
Next c
MsgBox mc
End Sub
 
Or if you no longer need the formula

'Range("B1").Formula = "=COUNTIF(n:n,""*john*"")"
Range("b1").Value = Application.CountIf(Columns("n"), "*john*")
 
Thanks Don, this new one requires the entire string to be UpperCase. Can it
be modified to be not case sensitive to any of the characters in the string?

Vaya con Dios,
Chuck, CABGx3
 
Sorry, didn't see your other suggestion when I did this post..........your
other one will do me just fine.........

Many thanks again,
Vaya con Dios,
Chuck, CABGx3
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top