Counting in a variable range

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi and thank you in advance.

I'm trying to count the word "Standard" in a series of ranges. Say A10-A15,
then maybe A40-A43...it keeps changing from 3 rows upto 10 rows.

Is there anyway to count in a range when the range keeps changing in the
amount of rows. Like it won't ever be only 5 rows, it may be 3 rows, 6 rows,
9 rows and then 2 rows.

Any help is greatly appreciated.

Thank you again.

Tim
 
Select the range you wish to count in

run this procedure to display a messagebox with the result

:======================================

Sub CountInSelection()

MsgBox Application.WorksheetFunction.CountIf(Selection, "Standard")

End Sub

:======================================

else declare a variable to th result and use as you wish. Let me know
if you need any more help for you use.

http://www.excel-ant.co.uk
 
Piece together the sections and then count within the union:

Sub example()
Dim r, rr As Range
Dim countit As Integer
Set r = Union(Range("A10:A15"), Range("A40:A43"))
countit = 0
For Each rr In r
If rr.Value = "Standard" Then
countit = countit + 1
End If
Next
MsgBox (countit)
End Sub

Alternatively, you can select the areas in the worksheet and then:

For Each rr in Selection
 
Thank you both for your response...I am working with your code now, it has
given me what I needed!

Thank you very very much! You guys are awsome!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top