In order to do some calculations on averages and differences of values in columns, I've defined a name, based on a range, but it seems to be completely going berserk:
I have a cell (D13), defined as Header_First _Answer, which contains the title of the column, and I have a value (currently being 69), which contains the number of entries, called Total_Count.
I've defined the entries of that column as another name: "All_First_Answered_Dates", defined as =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0) (start by the first entry under Header_First_Answer, take up to 69 entries, and define a range out of this).
In cell G5, I'm using that name in order to do some calculations (calculating averages), but this seems not to work (there is a #Value error).
After second comment from Rory: G5 formula and first formula evaluation result:
Formula:
=AVERAGE(IF(ISBLANK(All_First_Answered_Dates);TODAY();All_First_Answered_Dates) - All_Start_Dates)
First evaluation result:
=AVERAGE(IF(ISBLANK(#Value!);TODAY();All_First_Answered_Dates) - All_Start_Dates)
Hence, my conclusion:
After some checking I've found out that this is due to the name "All_First_Answered_Dates", which seems to be interpreted one time too many (or how do I explain this):
In different cells, I've entered the formula =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0) (which is exactly the meaning of "All_First_Answered_Dates"), and every time, using the Evaluate Formula feature, I see that the last but one result is correct: $D$14:$D$82. However, after that, another evaluation is done, turning this value into 43283 (in case the formula is entered in "J14"), 43300 (in case the formula is entered in "J15"), ..., and in case I enter this formula in a cell with row number lower than 14, I have the error value #Value (which explains the wrong result in cell G5).
If I simply put the formula =$D$14:$D$82 in any of the mentioned cells, then the content of some cells in column D are shown (which are dates, not values like 43283 or 43300).
It appears that declaring a range as =x:y, where x and y are formula results, is not working.
Does anybody know how I can define a range as a formula, which I can then use in order to define in a name?
I can imagine my explanation being quite complicated without an image, hence the attached screenshot. In there:
In cell J13, there is the formula =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0).
In cell J14, there is the same formula.
In cell K14, there is the formula =$D$14:$D$82.
For completion purposes, hereby a screenshot of the name manager, containing both mentioned names (the ones, selected in the name manager):
Edit after first comment:
The idea behind the range is the following:
1. Take the first row under Header_First_Answer, do not take any other column : OFFSET(Header_First_Answer;1;0)
2. Take the Total_Count's row under Header_First_Answer, do not take any other column : OFFSET(Header_First_Answer;Total_Count;0)
3. Define a range, based on those two cells, by putting a semicolon between them.
I was not aware of the height and width features of the Offset() worksheet function. I've implemented them, which makes the formulas much easier.
Unfortunately the problem still persists.
Thanks in advance
Dominique
I've just found the answer of what was going wrong:
The formula was meant to be an array formula. Something went wrong and while trying to debug, I accidently re-formatted the formula into a normal formula (I must have pressed "ENTER" instead of "Ctrl" + "Shift" + "ENTER") at some point.
I have re-applied array formula (using "Ctrl" + "Shift" + "ENTER"), getting a formula like:
{=AVERAGE(IF(ISBLANK(All_First_Answered_Dates);TODAY();All_First_Answered_Dates) - All_Start_Dates)}
(mind the braces {, })
Now everything is working fine.
I need to count all of the occurrences of a given value from a specific range of cells (containing strings or numbers), depending on a parameter stored in another cell.
I prepared a simple Excel table as an example (see attached image): let's say I want to count all of the occurrences of the VALUE "4" for the BASE "100". The result should be: 2 (C4 + C5).
Attached image
I tried to use COUNTIFS and FIND functions but with no results. The former only considers exact values (so the 4 in cell C5 will be ignored) while I seem to be unable to add another condition - the BASE column - to the latter.
Fact is I need to solve this with formulas only, no programming.
Thanks in advance for your help!
Use the SUMPRODUCT:
=SUMPRODUCT(($B$2:$B$10=100)*(ISNUMBER(SEARCH(4,$C$2:$C$10))))
There's a couple of other approaches, the simpler one is just to add another column which identifies matches for you, then have your count just sum the results of that column.
Solution image
So we put the values we want to find in some reference cells, the BASE match goes in G2, and the VALUE we're looking for goes in G3.
In column D we put a formula in D2:
"=IF(B2=$G$2,IF(ISERR(SEARCH($G$3,C2)),0,1),0)"
Returns 0 if the BASE matches and we can find at least one occurent of VALUE
B2=$G$2 - Does the BASE column match the BASE we're looking for
ISERR(SEARCH($G$3,C2)) - Does searching for the VALUE return an error (if it does, we know that VALUE isn't there)
Copy this formula to all the cells in column D, and then you can just use a simple SUM(D:D) to count the occurences where your conditions are met.
The neater but slightly more complex alternative is to use an array formula to do the match finding and counting all in one formula. This would look like this:
"{=SUM(IF(B:B=$G$2,IF(ISERR(SEARCH($G$3,C:C)),0,1)))}"
Pretty much the same as the formulas in column D, but now we use B:B and C:C in place of B2 / C2 etc. and stick the SUM around the whole thing. If you finish editing with Ctrl+Shift+Enter instead of just Enter, that'll make it an array formula.
Microsoft Array Formula Guidelines
NB: this WILL NOT count multiple occurences of 4 in a single VALUE cell.
p.s. Assuming you would want it to actually return 3 in this case (you missed the 4 in C7)
I've got a sheet with a transaction list. It includes a description of the transaction and the transaction total cost.
I'm looking for a way, without using Visual Basic, to use comma-separated keywords entered in a cell to search for all matching transactions, and then give their total value.
For example:
B4:B6 are keywords for look up.
C4 should look up in range B10:B26 for all cells containing any of the keywords in B1 (tesco OR co-op OR waitrose), and return the total value of the corresponding values in Range C10:C26. In this case it should SUM C11, C16, C21, C23, C25.
It's important to note that it shouldn't be case sensitive.
Can it be done?
You can do this with Array Functions. These functions operate similarly to "Sumifs" / "Countifs" / "Sumproduct": they perform functions normally designed to look at a specific cell, over an entire range of cells.
First let's deal with summing the total for "giffgaff" / "paypal":
In cell C5, use the following formula [As it is an Array formula, you must confirm by pressing CTRL + SHIFT + ENTER every time you edit the cell, instead of just ENTER] , and drag down to C6.
=sum(if(iserror(search(B5,$B$10:$B$26)),"",$C$10:$C26))
This looks at each row from B10:B26 (note that the entire column cannot be selected as an array formula calculates for all cells, even blank ones - so this drastically slows performance. You must specifically identify the rows you care about like this), and if there is an error when trying to search for the term in B4, that means the term does not appear on that particular row. If there is no error, it pulls the amount from column C. All of these rows are then summed together to get a single total.
Now to do the same for cell C4, you need to add in the complexity of first pulling apart each term which appears between a comma. I agree that #Tom Sharpe that you should probably do this in different cells to make it more clear what you're doing. This could be done by individually pulling terms between commas, and then having individual totals (which use the array formula above).
To do this most efficiently, I'd have use a helper column in column C, which will identify how many commas are in the text in column B, like so, in C4:
=len(B4)-len(substitute(B4,",",""))
This takes the length of B4, less the length of B4 where all commas have been replaced by blanks - giving the # of commas.
That formula can then be used to split out the words between commas, using the MID and SUBSTITUTE functions. Let me know if you need elaboration on how to do that. Once you have broken out the individual words, you can search with the Array function as above.
I have been breaking my head over this formula for sometime now. I have found a solution which is too big and not so convenient to use every time. So can any Excel Expert give me a solution/suggestion?
Column A contains 150 values. Column D to R contains a table in which I need to look up the values in A one by one. I want to return address of all the cells that contains the value.
For example, Value in A2 is present in cells D5, E15, H10, R3 then my result should be D5,E15,H10,R13.
Please Note that some columns may not contain the value of A2, I do not want them displayed.
Here is the formula I have written:
=CONCATENATE(
IF(A2=IF(COUNTIF(D:D,A2),VLOOKUP(A2,D:D,1,FALSE),""),ADDRESS(MATCH(A2,D:D,0),4,4),0),",",
IF(A2=IF(COUNTIF(E:E,A2),VLOOKUP(A2,E:E,1,FALSE),""),ADDRESS(MATCH(A2,E:E,0),5,4),0),",",
IF(A2=IF(COUNTIF(F:F,A2),VLOOKUP(A2,F:F,1,FALSE),""),ADDRESS(MATCH(A2,F:F,0),6,4),0),",",
IF(A2=IF(COUNTIF(G:G,A2),VLOOKUP(A2,G:G,1,FALSE),""),ADDRESS(MATCH(A2,G:G,0),7,4),0),",",
IF(A2=IF(COUNTIF(H:H,A2),VLOOKUP(A2,H:H,1,FALSE),""),ADDRESS(MATCH(A2,H:H,0),8,4),0),",",
IF(A2=IF(COUNTIF(I:I,A2),VLOOKUP(A2,I:I,1,FALSE),""),ADDRESS(MATCH(A2,I:I,0),9,4),0),",",
IF(A2=IF(COUNTIF(J:J,A2),VLOOKUP(A2,J:J,1,FALSE),""),ADDRESS(MATCH(A2,J:J,0),10,4),0),",",
IF(A2=IF(COUNTIF(K:K,A2),VLOOKUP(A2,K:K,1,FALSE),""),ADDRESS(MATCH(A2,K:K,0),11,4),0),",",
IF(A2=IF(COUNTIF(L:L,A2),VLOOKUP(A2,L:L,1,FALSE),""),ADDRESS(MATCH(A2,L:L,0),12,4),0),",",
IF(A2=IF(COUNTIF(M:M,A2),VLOOKUP(A2,M:M,1,FALSE),""),ADDRESS(MATCH(A2,M:M,0),13,4),0),",",
IF(A2=IF(COUNTIF(N:N,A2),VLOOKUP(A2,N:N,1,FALSE),""),ADDRESS(MATCH(A2,N:N,0),14,4),0),",",
IF(A2=IF(COUNTIF(O:O,A2),VLOOKUP(A2,O:O,1,FALSE),""),ADDRESS(MATCH(A2,O:O,0),15,4),0),",",
IF(A2=IF(COUNTIF(P:P,A2),VLOOKUP(A2,P:P,1,FALSE),""),ADDRESS(MATCH(A2,P:P,0),16,4),0),",",
IF(A2=IF(COUNTIF(Q:Q,A2),VLOOKUP(A2,Q:Q,1,FALSE),""),ADDRESS(MATCH(A2,Q:Q,0),17,4),0),",",
IF(A2=IF(COUNTIF(R:R,A2),VLOOKUP(A2,R:R,1,FALSE),""),ADDRESS(MATCH(A2,R:R,0),18,4),0))
As I said, this works but I am looking for a simpler and smaller formula.
Hint: Maybe using array can help?
Thanks in advance :)
What you are trying to accomplish is not a great fit for Excel formulas, but it can be done with a smaller, simpler formula dragged across 15 columns instead of 1 giant complicated formula that tries to do everything at once.
Assuming column A has 150 values (from A1 to A150), and there is a table going from D1 to R50...
Enter =S1&IFERROR(","&ADDRESS(MATCH($A1,D$1:D$50,0),COLUMN(D1)),"") into T1.
Drag the formula across to AH1.
Enter =RIGHT(AH1,LEN(AH1)-1) into AI1.
Select T1 to AI150 and press Ctrl-D.
Column AI1 will contain the results you are looking for.
How does this work?
The formula in T1 begins by taking the result of one cell to the left (which is blank). Then it concatenates this with the address of the first match in column D (prefixed by a comma). If there is no match, it just concatenates blank (""). As you drag this formula to the right, it keeps concatenating addresses as matches come up (or blank if there are none). When you get to the end, you will have looked for matches in all 15 column of your table.
The formula in AI1 just strips off the initial comma if there is one.