Solved

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

Posted on 2014-10-10
8
83 Views
Last Modified: 2014-10-10
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
Comment
Question by:kbay808
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 25

Expert Comment

by:ProfessorJimJam
ID: 40373617
can you upload a dummy file.  formula is kind of confusing with too many AND
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40373638
^ 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
 
LVL 50

Accepted Solution

by:
barry houdini earned 500 total points
ID: 40374174
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
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40374225
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:kbay808
ID: 40374230
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
 

Author Comment

by:kbay808
ID: 40374231
I did not see all of your updates.  I will try them out.
0
 

Author Closing Comment

by:kbay808
ID: 40374260
This worked.  Thank you very much.
0
 
LVL 50

Expert Comment

by:barry houdini
ID: 40374266
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now