Solved

Problem with counting

Posted on 2013-12-14
10
208 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 93

Expert Comment

by:John Hurst
ID: 39719372
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
ID: 39719379
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 93

Expert Comment

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

.... Thinkpads_User
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:Frank Freese
ID: 39719425
Thanks for the time. Let's see what other's will say.
0
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 39719459
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
 
LVL 81

Assisted Solution

by:byundt
byundt earned 500 total points
ID: 39719463
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
ID: 39719471
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
ID: 39719472
Thank you very much - I really appreciate it!
0
 
LVL 81

Expert Comment

by:byundt
ID: 39719489
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
ID: 39720189
Brad,
Thanks for the extra tip!
Frank
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
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 on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 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