Cell A1 has the formula =12+0+20+49+2+15+55 cell A1 shows the sum and that is as it needs to be, then I would like Cell A2 to show a count of how many items/individual numbers there are in the formula, ie 7. And show if a change is made in cell A1.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
How to Count number of items in a sum formula (97)
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » How to Count number of items in a sum formula (97)
- This topic has 12 replies, 4 voices, and was last updated 21 years, 3 months ago.
Viewing 3 reply threadsAuthorReplies-
WSHansV
AskWoody LoungerFebruary 23, 2004 at 11:41 pm #789118If you have Laurent Longre’s excellent Morefunc, you can use the FormulaText function from that add-in. Otherwise, create this user-defined function in a standard module (in Personal.xls if you like):
Function FormulaText(aCell As Range) As String
FormulaText = aCell.Cells(1).Formula
End FunctionThe following formula, entered as an array formula (i.e. confirm with Ctrl+Shift+Enter) will count the number of “+” characters in the formula and add 1:
With MoreFunc:
=SUM(IF(MID(FORMULATEXT(A1,,,TRUE),ROW(1:1024),1)=”+”,1,0))+1
With custom function:
=SUM(IF(MID(FORMULATEXT(A1),ROW(1:1024),1)=”+”,1,0))+1This is not very flexible – it doesn’t take other operators into account.
-
WSbookbox
AskWoody LoungerFebruary 24, 2004 at 5:27 am #789240Thank you gentlemen. You hit it right on. I knew someone here would have an answer. But now I remember why I quit coming in here. I do not understand two words out of ten of what you posted. I have no idea how to create a user-defined function in a standard module. Is that like a macro? Or what an option explicit is or how or where to create that.
Fortunately I was able to decipher Laurent Longre’s download (even tho I do not speak French). And type in the string. Both provided by Hans worked after the doing the download.
So again thanks for the link. This is a great board even if it is too advanced for this redhead.
-
WSHansV
AskWoody LoungerFebruary 24, 2004 at 8:20 am #789276Hi BookLady,
I’m glad you made it work. It is difficult to estimate how much detail a reply should contain, but you can always ask for more details or for an explanation. The Lounge tries to help users with all levels of experience.
You probably don’t need it any more, maybe don’t even want to know it, but here is a bit of background on custom functions. They are a bit like macros indeed, but instead of “running” them, you can use them in formulas, just like built-in functons such as SUM or COUNT.
To create a custom function:
- Select Tools | Macro | Visual Basic Editor… (or type Alt+F11) to activate the Visual Basic Editor.
- Select Insert | Module to create a new module. (This is called a “standard” module; there is also another type called a class module, but you don’t need to bother with that now.)
- Type the code, or copy it from a post and paste it. In my example, it was
Function FormulaText(aCell As Range) As String
FormulaText = aCell.Cells(1).Formula
End FunctionThis means: we define a function named FormulaText. You have to feed it one argument of type Range, that is, a cell reference. The result will be a string (a text). The function takes the first cell in the range passed to it, and returns the formula of that cell.
- The line Option Explicit in Steve’s code is usually not typed in by yourself. It is inserted automatically into every new module, provided that you have ticked “Require Variable Declaration” in the Tools | Options… dialog. In Visual Basic Code, you can use variables to store information temporarily; Option Explicit means that you *must* declare (announce) every variable before using it in a statement such as “Dim intPosition As Integer”.
[/list]
-
WSbookbox
AskWoody LoungerFebruary 24, 2004 at 5:16 pm #789602Thank you Hans. That is great and not too complicated. Having run in panic from all those modules in Visual Basic when trying to edit Macros, it is nice that Longre allready did that part for people like me
But thanks for the further instructions it is always good to learn something new. Am going to see how badly it is possible to screw up Xl by removing Longre’s and trying to use yours.
This is a great board as I said in my previous post. Just way too tech for me. But the other boards couldn’t come up with an answer. So I asked at my “Ace in the hole” backup board and sure enough not one but several answers.
-
WSunkamunka
AskWoody LoungerFebruary 24, 2004 at 6:07 pm #789620 -
WSunkamunka
AskWoody LoungerFebruary 24, 2004 at 6:07 pm #789621
-
-
WSbookbox
AskWoody LoungerFebruary 24, 2004 at 5:16 pm #789603Thank you Hans. That is great and not too complicated. Having run in panic from all those modules in Visual Basic when trying to edit Macros, it is nice that Longre allready did that part for people like me
But thanks for the further instructions it is always good to learn something new. Am going to see how badly it is possible to screw up Xl by removing Longre’s and trying to use yours.
This is a great board as I said in my previous post. Just way too tech for me. But the other boards couldn’t come up with an answer. So I asked at my “Ace in the hole” backup board and sure enough not one but several answers.
-
-
WSHansV
AskWoody LoungerFebruary 24, 2004 at 8:20 am #789277Hi BookLady,
I’m glad you made it work. It is difficult to estimate how much detail a reply should contain, but you can always ask for more details or for an explanation. The Lounge tries to help users with all levels of experience.
You probably don’t need it any more, maybe don’t even want to know it, but here is a bit of background on custom functions. They are a bit like macros indeed, but instead of “running” them, you can use them in formulas, just like built-in functons such as SUM or COUNT.
To create a custom function:
- Select Tools | Macro | Visual Basic Editor… (or type Alt+F11) to activate the Visual Basic Editor.
- Select Insert | Module to create a new module. (This is called a “standard” module; there is also another type called a class module, but you don’t need to bother with that now.)
- Type the code, or copy it from a post and paste it. In my example, it was
Function FormulaText(aCell As Range) As String
FormulaText = aCell.Cells(1).Formula
End FunctionThis means: we define a function named FormulaText. You have to feed it one argument of type Range, that is, a cell reference. The result will be a string (a text). The function takes the first cell in the range passed to it, and returns the formula of that cell.
- The line Option Explicit in Steve’s code is usually not typed in by yourself. It is inserted automatically into every new module, provided that you have ticked “Require Variable Declaration” in the Tools | Options… dialog. In Visual Basic Code, you can use variables to store information temporarily; Option Explicit means that you *must* declare (announce) every variable before using it in a statement such as “Dim intPosition As Integer”.
[/list]
-
-
WSbookbox
AskWoody LoungerFebruary 24, 2004 at 5:27 am #789241Thank you gentlemen. You hit it right on. I knew someone here would have an answer. But now I remember why I quit coming in here. I do not understand two words out of ten of what you posted. I have no idea how to create a user-defined function in a standard module. Is that like a macro? Or what an option explicit is or how or where to create that.
Fortunately I was able to decipher Laurent Longre’s download (even tho I do not speak French). And type in the string. Both provided by Hans worked after the doing the download.
So again thanks for the link. This is a great board even if it is too advanced for this redhead.
-
-
WSHansV
AskWoody LoungerFebruary 23, 2004 at 11:41 pm #789119If you have Laurent Longre’s excellent Morefunc, you can use the FormulaText function from that add-in. Otherwise, create this user-defined function in a standard module (in Personal.xls if you like):
Function FormulaText(aCell As Range) As String
FormulaText = aCell.Cells(1).Formula
End FunctionThe following formula, entered as an array formula (i.e. confirm with Ctrl+Shift+Enter) will count the number of “+” characters in the formula and add 1:
With MoreFunc:
=SUM(IF(MID(FORMULATEXT(A1,,,TRUE),ROW(1:1024),1)=”+”,1,0))+1
With custom function:
=SUM(IF(MID(FORMULATEXT(A1),ROW(1:1024),1)=”+”,1,0))+1This is not very flexible – it doesn’t take other operators into account.
-
WSsdckapr
AskWoody LoungerFebruary 23, 2004 at 11:58 pm #789137In addition to Hans’s suggestion you could use this function. This only takes the arithmetic operators into account +, -, *, / but it must be simple. IUf the formula is more complicated it could give weird results
Steve
Option Explicit Function CountItems(rCell As Range) As Integer Dim sFormula As String Dim sSigns As String Dim sClean As String Dim x As Integer Dim aWF As WorksheetFunction sSigns = "+-/*" Set aWF = Application.WorksheetFunction sFormula = rCell.Cells(1, 1).Formula sClean = sFormula For x = 1 To Len(sSigns) sClean = aWF.Substitute(sClean, Mid(sSigns, x, 1), "") Next CountItems = Len(sFormula) - Len(sClean) + 1 Set aWF = Nothing End Function
-
WSsdckapr
AskWoody LoungerFebruary 23, 2004 at 11:58 pm #789138In addition to Hans’s suggestion you could use this function. This only takes the arithmetic operators into account +, -, *, / but it must be simple. IUf the formula is more complicated it could give weird results
Steve
Option Explicit Function CountItems(rCell As Range) As Integer Dim sFormula As String Dim sSigns As String Dim sClean As String Dim x As Integer Dim aWF As WorksheetFunction sSigns = "+-/*" Set aWF = Application.WorksheetFunction sFormula = rCell.Cells(1, 1).Formula sClean = sFormula For x = 1 To Len(sSigns) sClean = aWF.Substitute(sClean, Mid(sSigns, x, 1), "") Next CountItems = Len(sFormula) - Len(sClean) + 1 Set aWF = Nothing End Function
Viewing 3 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Migrate off MS365 to Apple Products
by
dmt_3904
4 minutes ago -
Login screen icon
by
CWBillow
5 hours, 10 minutes ago -
AI coming to everything
by
Susan Bradley
1 hour, 18 minutes ago -
Mozilla : Pocket shuts down July 8, 2025, Fakespot shuts down on July 1, 2025
by
Alex5723
12 hours, 38 minutes ago -
No Screen TurnOff???
by
CWBillow
13 hours ago -
Identify a dynamic range to then be used in another formula
by
BigDaddy07
13 hours, 33 minutes ago -
InfoStealer Malware Data Breach Exposed 184 Million Logins and Passwords
by
Alex5723
1 day, 1 hour ago -
How well does your browser block trackers?
by
n0ads
11 hours, 27 minutes ago -
You can’t handle me
by
Susan Bradley
3 hours, 55 minutes ago -
Chrome Can Now Change Your Weak Passwords for You
by
Alex5723
4 hours, 4 minutes ago -
Microsoft: Over 394,000 Windows PCs infected by Lumma malware, affects Chrome..
by
Alex5723
1 day, 12 hours ago -
Signal vs Microsoft’s Recall ; By Default, Signal Doesn’t Recall
by
Alex5723
16 hours, 2 minutes ago -
Internet Archive : This is where all of The Internet is stored
by
Alex5723
1 day, 12 hours ago -
iPhone 7 Plus and the iPhone 8 on Vantage list
by
Alex5723
1 day, 13 hours ago -
Lumma malware takedown
by
EyesOnWindows
1 day, 1 hour ago -
“kill switches” found in Chinese made power inverters
by
Alex5723
1 day, 21 hours ago -
Windows 11 – InControl vs pausing Windows updates
by
Kathy Stevens
1 day, 21 hours ago -
Meet Gemini in Chrome
by
Alex5723
2 days, 1 hour ago -
DuckDuckGo’s Duck.ai added GPT-4o mini
by
Alex5723
2 days, 1 hour ago -
Trump signs Take It Down Act
by
Alex5723
2 days, 9 hours ago -
Do you have a maintenance window?
by
Susan Bradley
14 hours, 36 minutes ago -
Freshly discovered bug in OpenPGP.js undermines whole point of encrypted comms
by
Nibbled To Death By Ducks
1 day, 12 hours ago -
Cox Communications and Charter Communications to merge
by
not so anon
2 days, 13 hours ago -
Help with WD usb driver on Windows 11
by
Tex265
25 minutes ago -
hibernate activation
by
e_belmont
2 days, 22 hours ago -
Red Hat Enterprise Linux 10 with AI assistant
by
Alex5723
3 days, 1 hour ago -
Windows 11 Insider Preview build 26200.5603 released to DEV
by
joep517
3 days, 5 hours ago -
Windows 11 Insider Preview build 26120.4151 (24H2) released to BETA
by
joep517
3 days, 5 hours ago -
Fixing Windows 24H2 failed KB5058411 install
by
Alex5723
2 days, 1 hour ago -
Out of band for Windows 10
by
Susan Bradley
3 days, 9 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.