#Ref! error in excel formula - reference

I have used my formula
=SUM(D8:D11)-D12-D13-D14-D15
My main data in D1 to D11. Sometimes D12, D13, D14 & D15 data will be blank. Then I will remove the above D12, D13, D14, D15 data. Then It will be #ref! error.
Are there any solutions to avoid #ref! error.

Well part of the problem you will face will is the variability of the number of rows you have. I was looking at your number columns and I made the assumption that anything with a number less than 5 in column C you are adding, and anything greater than 4 in Column C you are subtracting. In the row where you have the total and you are having your error use the following.
=SUMIF(Reference Range, Criteria, Range to Sum from)
Which for you translates to:
=SUMIF($C1:$C9,"<"&5,D1:D9)-SUMIF($C1:$C9,">=5",D1:D9)
Because I did not lock the D column I can copy this one column to the right and the D references will change to E.
The main thing this is doing is taking the sum of everything that has a value in column C less than 5 and then subtracting the sum of everything that has a value of greater than or equal to 5 in column C.
Now if the assumption about those values in column C are incorrect let us know because we could also do it for subtracting anything starting with Depreciation.

Related

how to restart counting in excel after meeting specific value

In the below image I want to repeat the counting after it reaches 100 in a cell or shows zero and again starts from 20.i.e based on quantity.
If I give 1 in the D column then it multiplies 1*20 and gives 20 In the E column. similarly, it continues but when it reaches 100 it should rest or start counting from 20 from the next cell plz help me.
I think I need some more information on column E's formula. It looks like you are not just multiplying column D by 20 to get column E, because 1*20 doesn't ever equal 40 or 60 or 80.
My guess is that your formula for column E is, for example:
=D3*20 + E2, or in other words, multiply 1*20 and add the previous cell from column E.
If that's what you're doing, then try the below formula, which changes how a cell in column E is populated depending on what the value of the previous cell is:
=IF(E2<>80,D3*20+D2,0)
You'll need to set that formula in E3.
These are the formulas you need:-
[E2] =MOD(SUM(D$1:D2)*20,100)
[F2] =IF(E2=0,"PAY","PAID")
Copy both down as far as you require.

CountIf not counting values derived from formula

I couldn't find a matching answer already but happy to be redirected!
My issue is with countifs across two worksheets but I can replicate it in a smaller environment.
I have three columns of data (A-C): -
Column D has the formula =IF(A2="Closed",C2-B2,0).
That bit works, I now need to count how many took X number of days to close: -
Column G has the formula =COUNTIFS(A2:A11,"Closed",D2:D11,F2)
Looking at the pictures 41 and 49 should have a count of 1 right? What have I done wrong? All cells are formated as numbers.
Your formula in column G uses an absolute comparison to the value in column F.
The problem is that none of your values exactly match that value.
The duration column is formatted to show a value rounded to a day, but the underlying value is not the same as what is showing in the formatted cell.
Therefore, the formula in column G needs to factor in a range of values like this:
=COUNTIFS($A$2:$A$11,"Closed",$D$2:$D$11,">="&F2,$D$2:$D$11,"<"&F3)
In words: count all the cells where column A shows "Closed" and where the value in column D is between the value in F2 and the value in F3.
You will need to add an extra value in column F for anything above your biggest number in column F.
Check you output in Column D. It must be having decimals. If that is the case, you need to round the formulas in column D using ROUND formula.
=ROUND(IF(A2="Closed",C2-B2,0),0)
Rows 4 and 7 have status as "Open" and hence won't be counted by Countifs, i. e. change value of cells A4 and A7 to "Closed" to see updated results.
Also, fix your range $A$2:$A$11, etc. when using Countifs

Excel: Finding Difference in Two Lists

Say I have two lists in two columns in an Excel Worksheet...
Column A
Apple
Baseball
Carlos
Dad
and...
Column B
Baseball
Dad
Visual
Basic
I'm trying to compare what is in column A with what is in column B to find out what is in column A but not column B.I have a formula that works here that I can put in column C
=IF(COUNTIF($B:$B, $A2)=0, "No match in B", "")
My issue is how do I apply that formula to every row where Column A has an entry, and while doing that changing the $A2 in the formula to the corresponding row it's in. I can manually do this by going through and copying and pasting the formula to column C and changing $A2 to $A3,$A4 etc. Hoping theres a quick fix here so I don't have to do it for 400 rows!
Enter the below formula in Column C and drag down. You formula can be much simplified as below,
=IF(COUNTIF(B:B,A1),"Match","No Match")
COUNTIF returns a true if a match has been found, or in other words if the result is greater than 0. Returns false (0) if there is no match. Hence this can be written as mentioned above. (Checking if it is equal to 0 would not be necessary)
You could just drag the fill handle to as many rows you have.

How to find the maximum value of a given range, dependent on the value in a separate column

Screenshot of the Excel worksheet
I'm working with historic stock prices, and using eight columns I have:
Column A: High
Column B: Low
Column C: Close
Column D: Cx-Cx-4
Column E: Counts the number of consecutive positive numbers in column D
Column F: Counts the number of consecutive negative numbers in column D
Column G: Calculate the difference between the maximum of column A and minimum of column B within a given sequence.
As an example G1 should equal:
=max(A1:A5)-min(B1:B5)
G6 should equal:
=max(A6:A8)-min(B6:B8)
G9 should equal:
=max(A9:A11)-min(B9:B11)
And so on.
I'd like to know if it is possible to automate this calculation, possibly with the use of one or more additional columns.
Welcome to SO!
This may not be the most efficient solution as you need to add two helper columns, but if I understand your requirements correctly, then this idea should work well enough.
First, let's assume that there are 100 rows in your data set. Given that, enter the formula "=A100" in cell G100 and the formula "=B100" in cell H100. This sets up the boundary condition for the formulas in columns G and H. Now, in cell G99, enter this formula:
"=IF(E99="",G100,IF(E100="",A99,MAX(A99,G100)))"
What this formula does is set up a "running maximum" with the following logic:
If the cell in E99 is blank, copy the running maximum from G100, else:
If the cell in E99 is not blank but the cell in E100 is, set up a new running maximum from the cell in A99, else:
Take the maximum of A99 and G100 as the new running maximum.
Similarly, copy the following formula into cell H100:
"=IF(F99="",H100,IF(F100="",B99,MIN(B99,H100)))"
This follows the same logic as the previous formula, but takes the minimum of column B.
Copy or autofill these formulas to the top of the data set. This should now give you running maximum for column A and a running minimum for column B.
The next step is to calculate the difference. I notice from your question, that you only seem to be interested in calculating this difference at the top of each range (G1, G6, G9, etc.), rather than doing it in every row. Given that, we need a slightly more complicated formula.
The boundary condition for this formula is simply "=G1-H1" entered in cell I1. In cell I2, enter this:
"=IF(OR(AND(E2<>"",E1=""),AND(F2<>"",F1="")),G2-H2,"")"
How this works is that it check two conditions that indicate a range boundary:
E1 is blank and E2 is not
or
F1 is blank and F2 is not
If either of these conditions hold, the IF statement is true and "G2-H2" is diplayed, otherwise a blank cell is displayed. Now copy or autofill this formula to the bottom of the data set.
As a final step, you can now hide columns G and H if you don't need them displayed. This should now give you the results I think you're looking for. Please let me know if this doesn't work out for you.

extract the row number of a function result

I have a simple table with 5 names and 5 grades if you will.
In another column I order the grades using the LARGE function.
Now is there a way to know the row of each of the "ordered" grades to obtain something like that?
White 23 31 5
Red 15 23 1
Green 23 23 3
Blue 18 18 4
Grey 31 15 2
The column I can't calculate is the last one!
You should use the rank() function if you want to rank these grades. Not large().
=RANK(D2,$D$2:$D$6,1)
You can try this
=MATCH(LARGE(B1:B5,1),B1:B5,0)
The result is a number of row...
In Cell D1 Put =INDEX($A$1:$A$5,MATCH(C1,$B$1:$B$5,0))
Then in Cell D2 put =IF(D1<>INDEX($A$1:$A$5,MATCH(C2,$B$1:$B$5,0)),INDEX($A$1:$A$5,MATCH(C2,$B$1:$B$5,0)),INDEX($A$1:$A$5,MATCH(C2,$B$1:$B$5,0)+MATCH(C2,INDIRECT("$B$"&MATCH(C2,$B$1:$B$5,0)+1&":$B$5"),0)))
This will also work when duplicate Grades are present
But I Strongly Suggest using Sort as Follows:
*****Also: ***** Here is the explanation on the above Formulas.
To get the Row that contains the Number we are looking for (the number in Column C) you need yo use the Match() Function. We enter =MATCH(C1,B1:B5,0) in D1:
What this is doing: IS looking to the value in C1, this is 31
It is looking in Range("B1:B5"), And 0 is for an Exact match.
So when look for a match to C1 or 31 we get 5. This tells us that 31 is in Row 5
Now, to get the Value of Column A on Row 5 we use INDEX() Function as Follows:
We add to the =MATCH(C1,B1:B5,0) in D1 as =INDEX(A1:A5,MATCH(C1,B1:B5,0))
This will look in Range("A1:A5") for Row 5 (This is because =MATCH(C1,B1:B5,0) = 5)
And the result will be Grey
Now if we drag this formula down we will find the first problem:
Here are our 2 Issues:
1) We get an `N/A` error in the last row.
2) Although `Green` is only in `Range("A1:A5")` one time we see it twice
even though it would seem that `White` should be twice.
These are cause because:
1) We need to add `$` to the range that will remain the same so when we drag down
the formula is won't shift the range. As is the formula in `D5` is
`=INDEX(A5:A9,MATCH(C5,B5:B9,0))` and we receive the error *because*
`Range("A5:A9")` does not contain `15`, but the issue is we meant
to look in `Range("A1:A5")`
So we change the Formula as so: =INDEX($A$1:$A$5,MATCH(C1,$B$1:$B$5,0))
Take note that we do not use the $ on C1 in the formula cause we WANT this value to change as we move down.
But we still have the issue of double values when they shouldn't be there.
Because D1 is the first cell we won't change the formula in it. As anything that is equal to the greatest value is simply tied with it and I don't see any reason why the order of the tie would matter.
Instead we will start in D2 and enter =IF(D1<>INDEX($A$1:$A$5,MATCH(C2,$B$1:$B$5,0)),INDEX($A$1:$A$5,MATCH(C2,$B$1:$B$5,0)),INDEX($A$1:$A$5,MATCH(C2,$B$1:$B$5,0)+MATCH(C2,INDIRECT("$B$"&MATCH(C2,$B$1:$B$5,0)+1&":$B$5"),0)))
What this is doing is checking if the value of =INDEX($A$1:$A$5,MATCH(C2,$B$1:$B$5,0))
is not equal to the value in the row above. (being a sorted list means all double values would be on top of each other) and If it is NOT the same then use the value, but if it is the same we need to do a little more work.
If the value is not the same we use the Formula INDEX($A$1:$A$5,MATCH(C2,$B$1:$B$5,0)+MATCH(C2,INDIRECT("$B$"&MATCH(C2,$B$1:$B$5,0)+1&":$B$5"),0)))
Now to explain it I will use our example of double values. In D3 we find the formula: =IF(D2<>INDEX($A$1:$A$5,MATCH(C3,$B$1:$B$5,0)),INDEX($A$1:$A$5,MATCH(C3,$B$1:$B$5,0)),INDEX($A$1:$A$5,MATCH(C3,$B$1:$B$5,0)+MATCH(C3,INDIRECT("$B$"&MATCH(C3,$B$1:$B$5,0)+1&":$B$5"),0)))
And because we know that INDEX($A$1:$A$5,MATCH(C3,$B$1:$B$5,0)) will be equal to the above cell (White), and we have gone over how the if true works, I will focus on the if false value of: INDEX($A$1:$A$5,MATCH(C3,$B$1:$B$5,0)+MATCH(C3,INDIRECT("$B$"&MATCH(C3,$B$1:$B$5,0)+1&":$B$5"),0))
We know MATCH(C3,$B$1:$B$5,0) is the Row that contains the first instance of C3 in this case 23 and the row is Row 1 so we need to look for 23 in the row Under Row 1. So we use MATCH(C3,INDIRECT("$B$"&MATCH(C3,$B$1:$B$5,0)+1&":$B$5"),0) which is equal to MATCH("23", B2:B4,0) because we are adding a 1 to the row that has the 1st match for 23 or C3.
that will now return us the Value of 2 as, the value 23 is in the second row of Range("A2:A5"), Red is in Row 1 and Blue in Row 3 of that range as shown:
but we don't want Row 2 we know that 23 relates to Green and that Green is in Row 3 So we add the row the we last found the value 23 (1 or MATCH(C3,$B$1:$B$5,0))to the row we currently found it (2) and get Row 3.
Here is a formula approach based on the methodology outlined in this link. The final layout of this approach is shown below.
I have assumed that there is 1 header row and I use 2 helper columns (D & E). While additional rows can be added to the header, the table must begin in column A in order for the formulas in column E to work correctly.
Although the helper columns could be eliminated by consolidating their formulas into the formulas in column F, I do not recommend it: the resulting formulas would be a pain to maintain.
Formulas Needed
Cell C2: =LARGE(B:B,ROW(A2)-ROW($A$1)) [Copy down to bottom of data]
Cell D2: =MATCH(C2,B:B,0) [Copy down to bottom of data]
Cell E2: =D2
Cell E3: =IF(D3<>D2,D3,E2+MATCH(C3,INDIRECT("B"&(E2+1)&":B"&COUNTA(A:A)),0))
[Copy down to bottom of data]
Cell F2: =OFFSET($A$2,E2-ROW($A$2),0) [Copy down to bottom of data]
Explanation of Answer
There are four steps to getting the answer:
Sort the grades from highest to lowest (as you showed in your example data)
Create a partial ordering of the row numbers for the sorted grades
Get the row numbers for duplicate grades
Use that ordering to show the name for each sorted grade
Sort the grades from highest to lowest
As you have done, my sort uses the LARGE function, which returns the nth largest value in a range or array. As shown, the LARGE function in cell C2 takes the grades in column B. The "n" for LARGE is calculated as the current row number minus the number of rows in the header, in this case the 1 row for cell A1. When the formula is copied down, "n" progresses from 1 to 2 to 3, etc.
Partially order the grade row numbers
The next step is to determine the row numbers for the unsorted grades that correspond to the sorted grades.
To do that, I use the MATCH function to find where each of the sorted grades lies in the list of unsorted grades in column B. MATCH takes three arguments--the value to be matched, the range in which to make the match, and optionally, the type of match, with a value of 0 or FALSE for an exact match--and returns an index number which represents where in the lookup range the match is found (1 for the first row in the match range, 2 for the second row, etc.).
In the formula for cell D2 shown above, the MATCH function on the grade 31 returns 6 since 31 is in the sixth row of column B.
The result for cell D4 shows why it is only possible to get a partial ordering with this formula. While we are trying to lookup the row for the second instance of a grade of 23, the formula returns a value of 2, which corresponds to the row for the first instance of 23. That's because MATCH will always return the first match for 23 it finds, which is on row 2!
Get correct row numbers for duplicate grades
The next step is to get the correct row references for the duplicated row numbers in column D. The formulas that accomplish this are shown for the first three cells in column E of the table.
There are three cases that have to be dealt with in column E:
For the first (and possibly only) instance of the highest grade, it is possible to just use the row number calculated in cell D2.
The second case deals with the first instances of the row references of the remaining grades. For these the rows numbers calculated in column D can again be used (via the TRUE branch of the IF statement in the column E formulas). For example, in cell E2 -- which corresponds to the first instance of grade 23 -- the row number in cell D3 can be used.
The final case is the rows for duplicate grades. Here, the MATCH for each duplicate in column B is recalculated using a sliding range that excludes the previous matches for that grade. For example, for the duplicated grade of 23 in column C, the match is on the range B3:B6, rather than the range of B2:B6 used in the column D calculation.
Diplay the names in sorted order
This final step is straight forward: Get the name corresponding to the sorted grade. Here the OFFSET function is used; its arguments are a cell reference and the number of rows and columns from that reference that the desired value is to be found.

Resources