VBA Count Distinct Special Cells in a Range

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
1,177
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have a list of over 75,000 names. I am trying to get a unique count of any cell that has special characters in then except the comma (,). For the data below the count could be 7. Thanks in advance!

Billard, Ny'aniah S.D.
Kolman, Ja'Niyla A'Marie
Johnson, Dave
Holmes, Lord-Ken'th
Hook-Boullai, Jae'Zon Delomte
Jean-Franncois, Christ-Anne
Jones, Mike
Peterson, Ja'Nyhia Jer'Mirna
Wilson, Sanii'yah-lina Storla
Jones, AL
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Edit: After posting the function below, I am wondering about "unique count". Not sure what that might mean in this context as your sample didn't include any duplicate cell values.

Try this user-defined function. It should count a cell if it contains anything other than the 26 letters, space or comma.

Code:
Function CountSpecial(r As Range) As Long
  Dim a As Variant, itm As Variant
  
  a = r.Value
  With CreateObject("VBScript.RegExp")
    .Pattern = "[^A-Za-z ,]"
    For Each itm In a
      If .Test(itm) Then CountSpecial = CountSpecial + 1
    Next itm
  End With
End Function

Excel Workbook
AB
1Billard, Ny'aniah S.D.7
2Kolman, Ja'Niyla A'Marie
3Johnson, Dave
4Holmes, Lord-Ken'th
5Hook-Boullai, Jae'Zon Delomte
6Jean-Franncois, Christ-Anne
7Jones, Mike
8Peterson, Ja'Nyhia Jer'Mirna
9Wilson, Sanii'yah-lina Storla
10Jones, AL
Sheet1
 
Last edited:
Upvote 0
Perfect! Thanks Peter_SSs for your help and all the help you give to this site! I truly appreciate it!
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

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