Solved

Problem with counting

Posted on 2013-12-14
10
215 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
[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
  • 5
  • 3
  • 2
10 Comments
 
LVL 94

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 94

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
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!

 

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

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

726 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