
Santrauka
COUNTIF yra „Excel“ funkcija, skirta suskaičiuoti diapazono langelius, atitinkančius vieną sąlygą. COUNTIF galima naudoti skaičiuojant langelius, kuriuose yra datos, skaičiai ir tekstas. COUNTIF naudojami kriterijai palaiko loginius operatorius (>, <,, =) ir pakaitos simbolius (* ,?) daliniam atitikimui.
Tikslas
Skaičiuokite langelius, kurie atitinka kriterijusGrąžinimo vertė
Skaičiuojamas skaičius, žymintis ląsteles.Sintaksė
= COUNTIF (diapazonas, kriterijai)Argumentai
- diapazonas - skaičiuojamų ląstelių diapazonas.
- kriterijai - kriterijai, kurie kontroliuoja, kurios ląstelės turėtų būti skaičiuojamos.
Versija
„Excel 2003“Naudojimo užrašai
„Excel“ funkcija „COUNTIF“ skaičiuoja diapazono langelių skaičių, atitinkantį vieną pateiktą sąlygą. Kriterijai gali apimti loginius operatorius (>, <,, =) ir pakaitos simbolius (* ,?) daliniam suderinimui. Kriterijai taip pat gali būti pagrįsti kito langelio verte, kaip paaiškinta toliau.
COUNTIF yra aštuonių „Excel“ funkcijų grupėje, kuri loginius kriterijus padalija į dvi dalis (diapazonas + kriterijai). Todėl sintaksė, naudojama sudarant kriterijus, yra kitokia, o COUNTIF reikia langelių diapazono, jūs negalite naudoti masyvo.
„COUNTIF“ palaiko tik vieną sąlygą. Jei jums reikia taikyti kelis kriterijus, naudokite funkciją COUNTIFS. Jei reikia manipuliuoti diapazono argumento reikšmėmis kaip loginio testo dalimi, žr. Funkcijas SUMPRODUCT ir (arba) FILTER.
Pagrindinis pavyzdys
Aukščiau pateiktame darbalapyje ląstelėse G5, G6 ir G7 naudojamos šios formulės:
=COUNTIF(D5:D12,">100") // count sales over 100 =COUNTIF(B5:B12,"jim") // count name = "jim" =COUNTIF(C5:C12,"ca") // count state = "ca"
Pastaba COUNTIF neskiria didžiųjų ir mažųjų raidžių, „CA“ ir „ca“ traktuojamos vienodai.
Dvigubos kabutės ("") pagal kriterijus
Apskritai teksto reikšmės turi būti pateikiamos dvigubose kabutėse (""), o skaičiai ne. Tačiau kai loginis operatorius pridedamas prie skaičiaus, skaičius ir operatorius turi būti nurodomi kabutėse, kaip parodyta toliau pateiktame antrame pavyzdyje:
=COUNTIF(A1:A10,100) // count cells equal to 100 =COUNTIF(A1:A10,">32") // count cells greater than 32 =COUNTIF(A1:A10,"jim") // count cells equal to "jim"
Vertė iš kitos langelio
Vertę iš kitos ląstelės galima įtraukti į kriterijus naudojant sujungimą. Toliau pateiktame pavyzdyje COUNTIF grąžins A1: A10 reikšmių, kurios yra mažesnės nei reikšmė langelyje B1, skaičių. Atkreipkite dėmesį, kad mažesnis nei operatorius (kuris yra tekstas) yra įdėtas į kabutes.
=COUNTIF(A1:A10,"<"&B1) // count cells less than B1
Nelygu
To construct "not equal to" criteria, use the "" operator surrounded by double quotes (""). For example, the formula below will count cells not equal to "red" in the range A1:A10:
=COUNTIF(A1:A10,"red") // not "red"
Blank cells
COUNTIF can count cells that are blank or not blank. The formulas below count blank and not blank cells in the range A1:A10:
=COUNTIF(A1:A10,"") // not blank =COUNTIF(A1:A10,"") // blank
Dates
The easiest way to use COUNTIF with dates is to refer to a valid date in another cell with a cell reference. For example, to count cells in A1:A10 that contain a date greater than the date in B1, you can use a formula like this:
=COUNTIF(A1:A10, ">"&B1) // count dates greater than A1
Notice we must concatenate an operator to the date in B1. To use more advanced date criteria (i.e. all dates in a given month, or all dates between two dates) you'll want to switch to the COUNTIFS function, which can handle multiple criteria.
The safest way hardcode a date into COUNTIF is to use the DATE function. This ensures Excel will understand the date. To count cells in A1:A10 that contain a date less than April 1, 2020, you can use a formula like this
=COUNTIF(A1:A10,"<"&DATE(2020,4,1)) // dates less than 1-Apr-2020
Wildcards
The wildcard characters question mark (?), asterisk(*), or tilde (~) can be used in criteria. A question mark (?) matches any one character and an asterisk (*) matches zero or more characters of any kind. For example, to count cells in a A1:A5 that contain the text "apple" anywhere, you can use a formula like this:
=COUNTIF(A1:A5,"*apple*") // cells that contain "apple"
To count cells in A1:A5 that contain any 3 text characters, you can use:
=COUNTIF(A1:A5,"???") // cells that contain any 3 characters
The tilde (~) is an escape character to match literal wildcards. For example, to count a literal question mark (?), asterisk(*), or tilde (~), add a tilde in front of the wildcard (i.e. ~?, ~*, ~~).
Notes
- COUNTIF is not case-sensitive. Use the EXACT function for case-sensitive counts.
- COUNTIF only supports one condition. Use the COUNTIFS function for multiple criteria.
- Text strings in criteria must be enclosed in double quotes (""), i.e. "apple", ">32", "ja*"
- Cell references in criteria are not enclosed in quotes, i.e. "<"&A1
- The wildcard characters ? and * can be used in criteria. A question mark matches any one character and an asterisk matches any sequence of characters (zero or more).
- To match a literal question mark or asterisk, use a tilde (~) in front question mark or asterisk (i.e. ~?, ~*).
- COUNTIF requires a range, you can't substitute an array.
- COUNTIF returns incorrect results when used to match strings longer than 255 characters.
- COUNTIF will return a #VALUE error when referencing another workbook that is closed.
Related videos





