Solved

InStr function that counts all the numbers in a cell that fall within a specified range

Posted on 2011-09-22
6
320 Views
Last Modified: 2012-05-12
I have cells with values like: 19A, 20B, 26B,7C,20B,35D,14C, 21A,25C,26B,31A,17B  and i need a macro that tells me how many occurrences there are of numbers between 20 and 25.

I could split the strings into separate cells, and then create a helper row that strips out the letters. and use this:
[DQ3] = WorksheetFunction.CountIf([DR5:EH5], ">19") - WorksheetFunction.CountIf([DR5:EH5], ">25")

but I really need to do it as an InStr without going trough all that.

Thanks,
John
0
Comment
Question by:gabrielPennyback
[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
  • 2
  • 2
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
m4trix earned 500 total points
ID: 36584709
Something like this?
 sample.xlsm
0
 
LVL 23

Expert Comment

by:Michael74
ID: 36584729
This formula will do what you want

=SUM(COUNTIF(A1:A2, "*19*"),COUNTIF(A1:A2, "*20*"),COUNTIF(A1:A2, "*21*"),COUNTIF(A1:A2, "*22*"),COUNTIF(A1:A2, "*23*"),COUNTIF(A1:A2, "*24*"),COUNTIF(A1:A2, "*25*"))

The trick here is the use of the wildcard * in the countif condition

Michael
0
 
LVL 23

Expert Comment

by:Michael74
ID: 36584734
Sorry forgot to change the range in my formula. Here it is with the correct range input

=SUM(COUNTIF(DR5:EH5, "*19*"),COUNTIF(DR5:EH5, "*20*"),COUNTIF(DR5:EH5, "*21*"),COUNTIF(DR5:EH5, "*22*"),COUNTIF(DR5:EH5, "*23*"),COUNTIF(DR5:EH5, "*24*"),COUNTIF(DR5:EH5, "*25*"))

Michael
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 1

Author Comment

by:gabrielPennyback
ID: 36584969
Michael, thanks for the formulas but the number ranges are dynamic and sometimes very large so this probably won't work very well for me.

m4trix, your function is awesomely simple, and I was able to make a dynamic macro out of it which i will post here tomorrow if you're interested.

Thanks!
John
0
 
LVL 7

Expert Comment

by:m4trix
ID: 36585955
Thanks, and sure, post away! Perhaps someone down the road will find it helpful
0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 36590413
Here ya go. Thanks again.

- John
ges()
    Dim cel As Range, lft As Range, rgt As Range, rng As Range
    For Each cel In [AllY]
        Set lft = cells(cel.Row, [DR1].Column)
        Set rgt = lft.End(xlToRight)
        If lft = "" Then GoTo here
            If lft.Offset(0, 1) = "" Then
            Set rng = lft
            Else
            Set rng = Range(lft, rgt)
            End If
        cel = countValues(rng, cells(cel.Row, [Y_Lo].Column), cells(cel.Row, [Y_Hi].Column))
here:
    Next cel
End Sub

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
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…

710 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