I'm not sure if this is a duplicate question, I've tried looking around but I don't see any duplicates. Pardon me if I'm wrong.
I've got a simple formula that I stacked many times to give me my end result, but I feel like it's too long.
I have 2 questions:
1) What can I do to shorten this super-long mess of a formula I've come up with; and
2) Is there a better way to do it?
I need someone to at least point me in the right direction to get started.
This is the formula: =IF((COUNTIF(B1:B10,"VC1"))=1,IF((COUNTIF(B1:B10,"VC2"))=1,IF((COUNTIF(B1:B10,"VC3"))=1,IF((COUNTIF(B1:B10,"VCG1"))=1,IF((COUNTIF(B1:B10,"VCG2"))=1,IF((COUNTIF(B1:B10,"X"))=1,IF((COUNTIF(B1:B10,"XM"))=1,IF((COUNTIF(B1:B10,"XG"))=1,IF((COUNTIF(B1:B10,"P"))=2,"10","P"),"XG"),"XM"),"X"),"VCG2"),"VCG1"),"VC3"),"VC2"),"VC1")
Basically, I have text in cells B1 to B10, each with unique values.
In case it's needed, the values are (not in order): X, XM, XG, VCG1, VC1, VC2, VC3, VCG2, P, P.
A different cell will have the formula that I mentioned, to ensure that each cell has a very specific text defined, or else it'll show an error message.
Because of this, I also have another question:
3) What can I do to make it such that I can search (or COUNTIF) all the values from B1 to B10, and make sure that there's an exact number of values with very specific texts inside, without it going in order of the formula?
To explain this further, the formula does an IF, then a COUNTIF. If the COUNTIF succeeds, it will move on to the next COUNTIF inside the value for the result. Because of this, I can't print multiple "errors" at once, and it goes for each "error" one by one, which can be confusing to the end user.
It might be something else than what you want, but what if you use something like this?
=(COUNT(B1:B10;"VC1")=1)*1&
(COUNT(B1:B10;"VC2")=1)*1&
(COUNT(B1:B10;"VC3")=1)*1&
(COUNT(B1:B10;"VCG1")=1)*1&
(COUNT(B1:B10;"VCG2")=1)*1&
(COUNT(B1:B10;"X")=1)*1&
(COUNT(B1:B10;"XM")=1)*1&
(COUNT(B1:B10;"XG")=1)*1&
(COUNT(B1:B10;"P")=2)*1
it would create a string of zeroes and ones (false and true) and from this you would be able to identify if something is wrong and even how many errors occured and why.
Related
I was using this Index Match formula with no issues:
=INDEX('Rain Data For 9 Stations'!A:S,MATCH(RainWICSProximity!J100,'Rain Data For 9 Stations'!A:A,0),INDEX($N$4:$N$12,MATCH(H100,$M$4:$M$12,0)))
I added more data, and it now only returns some values, while returning #N/A for others, even though there is a value to return.
Index returns the value in a range.
What you are doing is =INDEX(MATCH(),INDEX(MATCH())). It works due to some luck, because sometimes the second Index() returns cell with value as well. However, if the second index returns cell with an empty value, then the first index has to return something like =Index(4,0), which is #N/A.
In general, try =Index(Match(),Match()).
To see where exactly the error is, select the cell with the formula, go to the Excel ribbon >Formulas>Evaluate Formula.
Then press a few times Evaluate Formula and see what happens:
See this answer for step-by-step formula evaluation.
#Vityata was correct, Index, Match, Match works wonderfully, also, my original formula does work.
The issue was, I had calculate set to Manual, not auto, in excel settings.
I believe you need to expand your range. I am not real familiar with Index Match but trying to learn to use it more, but I believe it is kind of like VLOOKUP. Your ranges $N$4:$N$12 and $M$4:$M$12 is where it is looking right? If so, those ranges are not expanding even though you added more data. So you need to expand it to like $M$4:$M$100 or whatever. Or expand it to find the last row which is what I usually do. like mine would be "$M$4:$M" & LastRow & "" or something like that.
So, say I have at cell A1:
=IF(A2=1,A2,0)
That OK, that's a tiny formula easy to understand.
If the formula starts to grow, I would have something like:
IF(...big formula here...=1,...repeat the big formula here...,0)
It's a dummy example but the key point here is that when I repeat the big formula at the TRUE condition position the formula double its size, what can hinder the formula debugging, for example.
Is there a way to not repeat the whole formula writting at this situation?
I don't want to use any macro/VBA to do this or any other 'helper' cells.
Thanks
In this particular case you don't have to use an IF statement, can just use
=--(A2=1)
Or for some other value, say 2,
=(A2=2)*2
These work if one of the results you want is zero.
It is a little more difficult if you have an IF statement like
=IF(A2>2,A2,2)
but you can often use MAX or MIN to avoid the IF statement
=MAX(A2,2)
If you had a chain of IF statements to divide the number in A2 into ranges like
=IF(A2>=2,20,IF(A2>=1,10,0))
You could replace it with a lookup
=IFERROR(VLOOKUP(A2,{1,10;2,20},2),0)
Sometimes you can replace a series of IF statements with CHOOSE, e.g. to return "Negative", "Positive" or "Zero"
=CHOOSE(SIGN(A2)+2,"Negative","Zero","Positive")
One tricky way I have seen is to use inverse functions one of which gives an error under certain conditions, so you could try
=IFERROR((SQRT(A2-2)^2)+2,2)
but I'm not sure I could recommend it as these methods can be vulnerable to rounding errors.
See this previous question
Create a helper column -- say, col X -- that calculates your big formula. Hide the column if you don't want to confuse other spreadsheet viewers.
Then your long, difficult to debug formula becomes IF(X1=1,...X1...,0).
First post, but I am stuck and was hoping for some help. What I am trying to do is use a nested IF formula to determine whether the value returned by a VLOOKUP matches specific text on another sheet in the same workbook. If it does, to then use the COUNTIFS function to determine the sum of instances that specific text contained in a specific cell appears on another sheet (also in the same workbook).
One part of these formulas seems to work, but when I combine it with others, it errors and I can't figure out why.
It's probably something simple, but I'd appreciate any help. Here's the part that seems to "work"
=IF(VLOOKUP($A3,'Sheet1'!$B:$D,3,FALSE)="All",
(COUNTIFS('Sheet2'!$U:$U,'Sheet3'!$A3,'Sheet2'!$C:$C,"MM/DD/YYYY")
+
(COUNTIFS('Sheet2'!$R:$R,'Sheet3'!$A3,'Sheet2'!$C:$C,"MM/DD/YYYY")))
If I put one more parenthesis, it works as is, but seems to omit some of the "All" Vlookup results... thus why I put works in quotations above. That might be an issue with my spreadsheet though, but felt I should include in case I'm just being idiotic. Regardless, when I input two additional IF statements, it errors.
The final formula I've crafted looks like this (double spaced for ease of reading only):
=IF(VLOOKUP($A3,'Sheet1'!$B:$D,3,FALSE)="All",
(COUNTIFS('Sheet2'!$U:$U,'Sheet3'!$A3,'Sheet2'!$C:$C,"MM/DD/YYYY")
+
(COUNTIFS('Sheet2'!$R:$R,'Sheet3'!$A3,'Sheet2'!$C:$C,"MM/DD/YYYY")))),
IF((VLOOKUP($A3,'Sheet1'!$B:$D,3,FALSE)="One",
(COUNTIFS('Sheet2'!$U:$U,'Sheet3'!$A3,'Sheet2'!$C:$C,"MM/DD/YYYY")),
IF((VLOOKUP($A3,'Sheet1'!$B:$D,3,FALSE)="Two",
(COUNTIFS('Sheet2'!$R:$R,'Sheet3'!$A3,'Sheet2'!$C:$C,"MM/DD/YYYY"),
IF((VLOOKUP($A3,'Sheet1'!$B:$D,3,FALSE)="Three",
(COUNTIFS('Sheet2'!$U:$U,'Sheet3'!$A3,'Sheet2'!$C:$C,"MM/DD/YYYY")),"0"))
Any ideas?
Thanks!
Ryan Olson
Just cleaned up some bracketing. Let me know how it goes as I didn't alter the formula otherwise.
=IF(VLOOKUP($A3,Sheet1!$B:$D,3,FALSE)="All",
COUNTIFS(Sheet2!$U:$U,Sheet3!$A3,Sheet2!$C:$C,"MM/DD/YYYY")+(COUNTIFS(Sheet2!$R:$R,Sheet3!$A3,Sheet2!$C:$C,"MM/DD/YYYY")),
IF(VLOOKUP($A3,Sheet1!$B:$D,3,FALSE)="One",
COUNTIFS(Sheet2!$U:$U,Sheet3!$A3,Sheet2!$C:$C,"MM/DD/YYYY"),
IF(VLOOKUP($A3,Sheet1!$B:$D,3,FALSE)="Two",
COUNTIFS(Sheet2!$R:$R,Sheet3!$A3,Sheet2!$C:$C,"MM/DD/YYYY"),
IF(VLOOKUP($A3,Sheet1!$B:$D,3,FALSE)="Three",
COUNTIFS(Sheet2!$U:$U,Sheet3!$A3,Sheet2!$C:$C,"MM/DD/YYYY"),"0"))))
I’ve put on formula below to leave this cell empty if cell AQ2184 is empty, but still gives me one in some random instances. Other times it leaves it empty. There is a formula In the cells to count which I guess it’s why it counts the cell as if there is character even that it’s empty….what I find very confusing is that it only does it the odd times, but when it does it drives me crazy because I don’t know why it’s behaving like this. If I take the formula off and simply enter the number/s, it works fine, but I need the formula in column AS. I've tried changing the format to number, general and text, but no matter what I do it always does the odd thing in one row or another......why? is there anything I could do?
=IF(ISBLANK(AQ2184),"",COUNT(AS2184))
Also tried; =IF(AS2190>=1,"1","") but it doesn't behave
Try this:
IF(AQ2184="","",COUNT(AS2184))
I would like to have part of an excel formula be dynamic, other than a cell reference.
For instance, suppose that in column A (cells A1:A99) I have a bunch of numbers, and I want to know how many of those numbers are greater than 50.
If I wanted this calculation to be static, I could simply use one of the following:
=COUNTIF($A$1:$A$99,">50")
=SUM(IF($A$1:$A$99>50,1,0))
=SUM(($A$1:$A$99>50)*1)
I mention all three because my actual formula is hairy and a bit of a mix of the second and the third. (After all, perhaps something will work with COUNTIF but not with the others.)
Now, I want to be able to type my condition in another cell (say C1). So if I type ">50" in C1, my calculation will be as above, but if I type "<100" I will count how many entries of column A are less than 100.
Is this possible? (I am using Excel 2003 on Windows XP.)
There may be something that I'm missing.
If you give
=COUNTIF($A$1:$A$99,C1)
in any cell, and then in cell C1 you type >50 or <100
don't you get what you want?
Use INDIRECT
=INDIRECT(COUNTIF($A$1:$A$99,">50"))
is same as
=COUNTIF($A$1:$A$99,">50")
But, as you identified, the former, you can generate within the excel cells! I do it all the time, for such things.
I usually solve this by adding another column carrying the result of a complex logical expression, like
=AND(OR(C3<D3;E3>=100);A3=VLOOKUP(B3;Sheet2!$A$2:$B$212;2;FALSE))
this formula is in all rows of -say- column F - note: no IF needed here!
then I calculate a complex conditional sum across column E using =SUMIF() like
=SUMIF(F2:F57;TRUE;E2:E57)
I know that some users say "I do not want to change my design. That's ok; my argument is that I have better control over the condition, I can work on the condition seperately from summing up or other functions that rely on that condition, and I can filter records for TRUE or FALSE to look at the subsets and have a rapid overview if the formula makes sense
hope that helps Good luck MikeD