VBA Count of Range of Numbers (ie, 0-14) in a Column

CatLadee

New Member
Joined
Sep 7, 2018
Messages
29
Please help me update the code below so that the counts work on the ranges of numbers (arrows below) Thanks!

Code:
Sub Metrics()

Dim ws As Worksheet
Set ws = Worksheets("Master")
''
    Total = Application.WorksheetFunction.CountIf(ws.Range("i:i"), ">0")
    Zeroto14 = Application.WorksheetFunction.CountIf(ws.Range("i:i"), "0-14")   <---
    Fifteento29 = Application.WorksheetFunction.CountIf(ws.Range("i:i"), "15-29")   <---
    Thirtyplus = Application.WorksheetFunction.CountIf(ws.Range("i:i"), ">30")


    Range("a1").Select
    Sheets("Tool | Summary").Select
    Range("J6") = Total
    Range("J7") = Zeroto14
    Range("J8") = Fifteento29
    Range("J9") = Thirtyplus
'
'
'
'    Worksheets("Tool | Summary").Select
'    Range("A1").Select
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try this

Code:
Zeroto14 = Application.WorksheetFunction.CountIf[COLOR=#ff0000]s[/COLOR](ws.Range("i:i"), ">=0", ws.Range("i:i"), "<=14")
Fifteento29 = Application.WorksheetFunction.CountIf[COLOR=#ff0000]s[/COLOR](ws.Range("i:i"), ">=15", ws.Range("i:i"), "<=29")
 
Upvote 0
Try like
Code:
Zeroto14 = Application.CountIfs(ws.Range("i:i"), ">=0", ws.Range("i:i"), "<=14")

Beaten2it
 
Last edited:
Upvote 0
Very true & all that counts is the OP gets some help :)
 
Upvote 0
This works perfectly! Thank you so much!


Try this

Code:
Zeroto14 = Application.WorksheetFunction.CountIf[COLOR=#ff0000]s[/COLOR](ws.Range("i:i"), ">=0", ws.Range("i:i"), "<=14")
Fifteento29 = Application.WorksheetFunction.CountIf[COLOR=#ff0000]s[/COLOR](ws.Range("i:i"), ">=15", ws.Range("i:i"), "<=29")
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,812
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top