Solved

Problem with counting

Posted on 2013-12-14
10
174 Views
Last Modified: 2013-12-15
Folks,
In Column A of the attached workbook I have various IP addresses, some with one to three "xxx". In D3:D5 I have an array formula using SUM, MID, COLUMN functions.

I'm not getting the expected results. I am wanting to know how many IP address's have one "x", two, "xx" and three "xxx". I get the three "xxx" but that all.
COUNT.xlsm
0
Comment
Question by:Frank Freese
  • 5
  • 3
  • 2
10 Comments
 
LVL 90

Expert Comment

by:John Hurst
Comment Utility
The cells are formatted as General. Try formatting the cells you are test as Text.  I think they need to be formatted as Text for MID, LEFT and RIGHT to work.

... Thinkpads_User
0
 

Author Comment

by:Frank Freese
Comment Utility
I changed the formatting to text but the results were the same.
By the way I am not using RIGHT but I am using COLUMN
0
 
LVL 90

Expert Comment

by:John Hurst
Comment Utility
I don't know. You are using Array formulas and I have not used these.

.... Thinkpads_User
0
 

Author Comment

by:Frank Freese
Comment Utility
Thanks for the time. Let's see what other's will say.
0
 
LVL 80

Accepted Solution

by:
byundt earned 500 total points
Comment Utility
Why not use COUNTIF with wildcards?

=COUNTIF(A:A,"*xxx*")           count of cells containing xxx
=COUNTIF(A:A,"*xx*") - K2     count of cells containing xx     (K2 is count above)
=COUNTIF(A:A,"*x*") -SUM(K2:K3)       count of cells containing x   (K2 & K3 are counts above)
COUNT-Q28318483.xlsm
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 80

Assisted Solution

by:byundt
byundt earned 500 total points
Comment Utility
Thinkpads_User,
If you change the format of a cell, it does not change the contents of that cell. If they were originally numbers, changing the format to text does not make those cells contain text. And vice-versa.

The array formulas were double or triple counting cells when looking for "xx" or "x". This is because they were getting substrings from the cell starting at each possible position. So a cell containing "xxx" would trigger two "xx" counts--one for the first two x and the second for the last two.

Similarly, a count for "x" would be triggered three times in a cell containing "xxx" and twice in one containing "xx".

COUNTIF only counts a cell once, no matter how many times the pattern is matched. What's more, you don't need to array-enter the formula.

Brad
0
 

Author Comment

by:Frank Freese
Comment Utility
Brad,
Thanks for the explanation. Why didn't I use COUNTIF? Let's just say I had another senior moment and then I wanted to experiment more with using arrays.
Great solution - great job!
0
 

Author Closing Comment

by:Frank Freese
Comment Utility
Thank you very much - I really appreciate it!
0
 
LVL 80

Expert Comment

by:byundt
Comment Utility
fh_freese,
If you really want to use an array formula, consider one like this to find the number of cells containing "x" (but not "xx" or "xxx"):
=SUM(ISNUMBER(SEARCH("x",A2:A11)) - ISNUMBER(SEARCH("xx",A2:A11)))

Brad
0
 

Author Comment

by:Frank Freese
Comment Utility
Brad,
Thanks for the extra tip!
Frank
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now