Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 99
  • Last Modified:

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)
0
kbay808
Asked:
kbay808
  • 3
  • 2
  • 2
  • +1
1 Solution
 
ProfessorJimJamCommented:
can you upload a dummy file.  formula is kind of confusing with too many AND
0
 
Glenn RayExcel VBA DeveloperCommented:
^ 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
0
 
barry houdiniCommented:
As Glenn says, you can take out the redundant ANDs and you'd get this version which should give the same results as you get now

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

To do the change you want I assume that any match in the range Sites!D1:D53 will be sufficient, in which case use the COUNTIF function like this:

=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)

regards, barry
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Glenn RayExcel VBA DeveloperCommented:
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?
0
 
kbay808Author Commented:
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.
0
 
kbay808Author Commented:
I did not see all of your updates.  I will try them out.
0
 
kbay808Author Commented:
This worked.  Thank you very much.
0
 
barry houdiniCommented:
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
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now