Counbt Formula

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,605
Office Version
  1. 2021
Platform
  1. Windows
I would like a formula to count the number of units as follows based on the type in Col H

0-7
8-30
31-60
60 days plus

Your assistance in this regard is most appreciated

Excel Workbook
CDEFGHI
3KNB11102HONDA JAZZ 1.5 EXZBD972KLZJHPXGE8880AS20016947441501U15
4KNB11134FORD Figo 1.4 Sigma AmbienteCJ20CKKLZPXAJ1LYPXRJ1CT5944347441515N30
5KNB11227RENAULT LOGAN LOGAN 1.6 EXPRESSIONZWN573KLZPXA1LSRADDAZD1250847441516N45
6KNB11117MERCEDES-BENZ Mercedes CRZS062KLZWDC2030422R18583247441530U50
7KNB11118MERCEDES-BENZ Mercedes CRZS062KLZWDC2030422R18583347441531U51
8KNB11119MERCEDES-BENZ Mercedes CRZS062KLZWDC2030422R18583447441532N52
9KNB11120MERCEDES-BENZ Mercedes CRZS062KLZWDC2030422R18583547441533U53
10KNB11121MERCEDES-BENZ Mercedes CRZS062KLZWDC2030422R18583647441534U54
11
Sheet1
 
i think that i over thought this

here is a simpler way (less flexible though)
Code:
Sub test()

    Dim cel As Range


    Dim lo As Integer, mid As Integer, hi As Integer, max As Integer
    
    lo = 0: mid = 0: hi = 0: max = 0


    For Each cel In Range("g1:g8")
        Select Case cel
            Case 0 To 7
                lo = lo + 1
            Case 8 To 30
                mid = mid + 1
            Case 31 To 60
                hi = hi + 1
            Case Is > 60
                max = max + 1
            Case Else
                MsgBox "invalid number in cell"
        End Select
'        Debug.Print cel
    Next cel

    Debug.Print lo & vbTab & mid & vbTab & hi & vbTab & max 

End Sub
 
Upvote 0
Thanks for the help much appreciated. How would one compute this manually using countifs?
 
Upvote 0
i was just looking at that

countif allows a single"criteria range":"criteria" pair

countifs allows multiple "criteria range":"criteria" pairs (just do two different criteria on the same criteria range)

put these formulas into the four "result" cells

the two groups give the same result (the one on right is more legible, but it probably does more calculations)
Code:
=COUNTIFS(G[COLOR=#333333]1:G8[/COLOR],">=0",G[COLOR=#333333]1:G8[/COLOR],"< 8")                    =COUNTIFS(G[COLOR=#333333]1:G8[/COLOR],">= 0",G[COLOR=#333333]1:G8[/COLOR],"<= 7")
=COUNTIFS(G[COLOR=#333333]1:G8[/COLOR],"> 7",G[COLOR=#333333]1:G8[/COLOR],"<31")                    =COUNTIFS(G[COLOR=#333333]1:G8[/COLOR],">= 8",G[COLOR=#333333]1:G8[/COLOR],"<=30")
=COUNTIFS(G[COLOR=#333333]1:G8[/COLOR],">30",G[COLOR=#333333]1:G8[/COLOR],"<61")                    =COUNTIFS(G[COLOR=#333333]1:G8[/COLOR],">=31",G[COLOR=#333333]1:G8[/COLOR],"<=60")
 =COUNTIF(G[COLOR=#333333]1:G8[/COLOR],">60")                                 =COUNTIF(G[COLOR=#333333]1:G8[/COLOR],">=61")
 
Upvote 0

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