Solved

How to create a user function to count for a particular characters in a cell

Posted on 2016-10-06
8
56 Views
Last Modified: 2016-10-07
I had this question after viewing Count specific characters in a cell or range in Excel.

I need the function to be available for all my spreadsheets.
0
Comment
Question by:Alex972
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 41832143
Is there some reason why you couldn't use the formula solution provided in that previous question?

If you want to know how many instances of the letter "o" occur in A1:

=LEN(A1)-LEN(SUBSTITUTE(A1,"o",""))

If you want to know how often the letter "o" occurs in the range A1:A3, use this array formula:

{=SUM(LEN(A1:A3)-LEN(SUBSTITUTE(A1:A3,"o","")))}

To enter an array formula, DO NOT type the curly braces, and use Ctrl+Shift+Enter instead of Enter to finish the formula.
0
 
LVL 1

Author Comment

by:Alex972
ID: 41832176
I want the function be available in all the spreadsheets without re-entering the function each time.
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 41832191
Even if this were deployed as a UDF, you would still have to write a formula using that UDF in all of your workbooks.

Going the UDF route only makes sense if the functionality you need is not readily available through the built-in functions.
0
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
LVL 31

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41832282
Patrick is right here.
Even the link you provided offered a inbuilt formula based solution which you can use in any of your workbooks.
But if for any reason you want to use a UDF, you may place the following code on a Standard Module of a blank workbook and save it as an Excel Add-in (.xlam) and then enable that Add-in from the Developer Tab --> Add-Ins.

Function CountCharacters(cell As Range, Character As String) As Long
   CountCharacters = Len(cell.Value) - Len(Replace(cell.Value, Character, ""))
End Function

Open in new window

Then you can use the above function on the worksheet as below....
=CountCharacters(A1,"character to count")

Open in new window

0
 
LVL 1

Author Comment

by:Alex972
ID: 41832815
I have gone through the steps several times, but I must be doing something wrong.  While it shows up in the Add-Ins list, it doesn't show up when I start typing the function name.

"But if for any reason you want to use a UDF, you may place the following code on a Standard Module of a blank workbook and save it as an Excel Add-in (.xlam) and then enable that Add-in from the Developer Tab --> Add-Ins."
0
 
LVL 31

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 500 total points
ID: 41832964
Please make sure that you followed the steps exactly shown in the following video.
http://www.screencast.com/t/JjKPiFjk
0
 
LVL 1

Author Closing Comment

by:Alex972
ID: 41833803
Both the answer and video were very good. I was not familiar with Inserting a Module.
0
 
LVL 31

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41833867
You're welcome Alex! Glad to help.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question