Link to home
Start Free TrialLog in
Avatar of kbay808
kbay808Flag for United States of America

asked on

How to modify my formula to compare a cell to a range?

I am trying to replace the "(O2=$U$1)" portion of the below formula so that I can compare the value in cell "O2" with the range "Sites!D1:D53".

=SUM(AND(AND(O2=$U$1),AND(L2>=IF(RIGHT(S2,3)="VIP",0.5,11),L2<=IF(RIGHT(S2,3)="VIP",1,14),E2<>"NO KPP",F2<>"Closed")),A1)
Avatar of Professor J
Professor J

can you upload a dummy file.  formula is kind of confusing with too many AND
^ Agreeing with ProfessorJimJam.  The original function has too many - an incorrect - use of AND in the SUM function.  I'm surprised it yields any values.

What values are actually to be summed?

-Glenn
ASKER CERTIFIED SOLUTION
Avatar of barry houdini
barry houdini
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, Barry.  

The issue I see is that, even after the redunant AND functions are removed, the whole SUM function is trying to sum up statements that evaluate to TRUE or FALSE:

=SUM(
    AND(
        COUNTIF(Sites!D1:D53,O2)>0,
        L2>=IF(RIGHT(S2,3)="VIP",0.5,11),
        L2<=IF(RIGHT(S2,3)="VIP",1,14),
        E2<>"NO KPP",
        F2<>"Closed"),
A1)

Why bother summing A1?
Avatar of kbay808

ASKER

I tried to make a sample file, but it's pulling sensitive data from multiple files.  I have been unable to duplicate it where the formula works.  The formula is used in a helper column to count the number of records that meet a certian criteria.  Please let me know if this is not possible without a sample file and I will delete this question.
Avatar of kbay808

ASKER

I did not see all of your updates.  I will try them out.
Avatar of kbay808

ASKER

This worked.  Thank you very much.
Hello Glenn,

I agree that it seems an odd formulation - the formula is effectively returning the value of A2, plus 1 if the AND function returns TRUE, because, for example,

=SUM(TRUE,4) = 5

It might be clearer to write it like this

=IF(AND(COUNTIF(Sites!D1:D53,O2)>0,L2>=IF(RIGHT(S2,3)="VIP",0.5,11),L2<=IF(RIGHT(S2,3)="VIP",1,14),E2<>"NO KPP",F2<>"Closed"),1,0)+A2

Perhaps kbay808 can confirm that the formula is supposed to work like that?

Of course that latter version would fail if A2 contains text, so the SUM approach has some merit if deliberately used to avoid an error in that situation

regards, barry