Formula not working for me

%3CLINGO-SUB%20id%3D%22lingo-sub-1982630%22%20slang%3D%22en-US%22%3EFormula%20not%20working%20for%20me%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1982630%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20trying%20to%20get%20my%20spreadsheet%20to%20count%20how%20many%20zip%20codes%20that%20I%20have%20that%20are%20%22%26gt%3B%3D%22%20to%20a%20certain%20cell%20but%20%22%26lt%3B%3D%22%20another%20cell%20with%20the%20following%20formula%20and%20it%20is%20not%20working.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3DCOUNTIFS(G2%3AG302%2C%22%26gt%3B%3D%22%26amp%3BH2%2CG2%3AG302%2C%22%26lt%3B%22%26amp%3BI2)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1982630%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1982647%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20not%20working%20for%20me%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1982647%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F899904%22%20target%3D%22_blank%22%3E%40mehoop%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20theory%20it%20shall%20work%20if%20you%20mean%20AND%20condition%20and%20depends%20on%20if%20all%20are%20texts%2C%20or%20all%20are%20numbers%20or%20mix.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1982648%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20not%20working%20for%20me%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1982648%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F899904%22%20target%3D%22_blank%22%3E%40mehoop%3C%2FA%3E%26nbsp%3BCould%20work%20but%20may%20depend%20on%20how%20the%20zip-codes%20look%20like.%20Just%20numbers%3F%20Including%20characters%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1982650%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20not%20working%20for%20me%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1982650%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat%20could%20be%209345667%20as%20text%20in%20one%20place%20and%26nbsp%3B9345667%20as%20number%20in%20another%20-%20fault.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1982702%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20not%20working%20for%20me%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1982702%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F899904%22%20target%3D%22_blank%22%3E%40mehoop%3C%2FA%3E%26nbsp%3BAs%20you%20are%20using%20comparison%20operators%20%22%26gt%3B%3D%22%2C%20both%20the%20zip%20code%20and%20fixed%20values%20cells%20I2%20and%20H2%20should%20be%20numbers.%20If%20zicode%20is%20like%20600-2000%2C%20Excel%20will%20treat%20it%20as%20text%20and%20can't%20validate%20the%20'greater%20than%20or%20less%20than'%20equal%20conditions%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

I am trying to get my spreadsheet to count how many zip codes that I have that are ">=" to a certain cell but "<=" another cell with the following formula and it is not working.

 

=COUNTIFS(G2:G302,">="&H2,G2:G302,"<"&I2)

9 Replies

@mehoop 

In theory it shall work if you mean AND condition and depends on if all are texts, or all are numbers or mix.

@mehoop Could work but may depend on how the zip-codes look like. Just numbers? Including characters?

@Riny_van_Eekelen 

That could be 9345667 as text in one place and 9345667 as number in another - fault.

@mehoop As you are using comparison operators ">=", both the zip code and fixed values cells I2 and H2 should be numbers. If zicode is like 600-2000, Excel will treat it as text and can't validate the 'greater than or less than' equal conditions 

@sankalp_parmar 

Why not, ="600-2000">"600-1999" returns TRUE

@Sergei Baklan Because both are treated as text value. Although if you put "600-2000">"600-1999" , it returns true, it does not mean that 1st one is actually greater than 2nd. Lets take "A" and "B" and put formula in a cell as ="B">"A" . This will give True because in alphabets B comes after A. In simiar manner "600-2000">"600-1999". Its more of sorting

@sankalp_parmar 

It's more about binary representation of data

@mehoop 

The following

= LET(
  numeric,  VALUE(SUBSTITUTE(zip, "-", "")),
  filteredZIP, FILTER(zip, (numeric > startN) * (numeric <= endN) ),
  COUNTA(filteredZIP) )

would convert hyphenated zips to numbers and use the numeric values as a filter prior to counting.

@mehoop 

It's still desirably to know how your zip codes looks like. Let assume they are all texts which represent numbers like in this sample

image.png

COUNTIFS() automatically transforms texts which looks like numbers into numbers. Thus in our sample in comparison text "192000" will be in background converted into the number 192000. There is the know trick to avoid that, to add CHAR(174) to such text

=COUNTIFS(F2:F6,">="&F9&CHAR(174),F2:F6,"<="&F10&CHAR(174))

or to work with SUMPRODUCT() which works as expected without surprises

=SUMPRODUCT((F2:F6>=F9)*(F2:F6<=F10))