Excel: COUNTIF + OFFSET in another worksheet - excel

Not sure why this wouldn't work:
COUNTIF(OFFSET(OtherSheet!F5,0,0,4,1),"<10")
Trying to count values less than 10 in 4 rows of another worksheet. Of course, I can use OtherSheet!F5:F8 instead of the OFFSET like so:
COUNTIF(OtherSheet!F5:F8,"<10")
and this works fine. but I'm trying to work up to where the "4" is dynamically determined. But, I can't even seem to get the OFFSET to work correctly when the range is in another spreadsheet.
Thanks!
Derek

Don't know about OFFSET, but it is volatile and I avoid it whenever possible. I would use INDEX, which is not volatile:
=COUNTIF(Sheet1!$F$5:INDEX(Sheet1!$F$5:$F1040000,4),"<10")
Replace the 4 with the cell in which you want to place the size of the array.

Related

Excel reference a range based on a string

I would like to input a number in a range from another sheet and I don't know how to do it.
The function:
=PERCENTRANK.INC(sheet1!$C$6:$C$**96**;sheet1!$C$6))
For example: The result of this function should be in a range of 10 days. So the range would be sheet1!M6:M16 (not sheet1!M6:M96)
I want input different numbers on the "96" space.
And I have a large matrix so it's impossible to do it manually.
Thank you so much!!
Avoid the use of volatile INDIRECT and OFFSET set-ups when a perfectly good non-volatile INDEX set-up is available.
=PERCENTRANK.INC(Sheet1!C6:INDEX(Sheet1!C:C,G3),Sheet1!C6)
=Average(indirect("sheet1!M6:M"&A1)) in A1 put 96
You may want to replace the range inside the average: =AVERAGE(FILTER(…)) where you can define a range by certain criteria.
edit:
If you want to use the absolute cell reference, see the answer from Zorigt.
Alternatively, you could also use the OFFSET function to define your range starting from a reference cell (e.g. 10 rows for 10 days)
With the filter you could define e.g. from which day to which day and/or any other criteria
If you want dynamic range as per the input you will give better make use of the address function with indirect. indirect takes static cell reference.
=ADDRESS($C$3+6,3)
Result: $C$16
=PERCENTRANK.INC($C$6:INDIRECT(ADDRESS($C$3+6,3)),C6)
however this function doesn't ignore the values outside the range that you gave.
so to overcome this problem you can check if the range you gave and the current row/cell in the formula is greated then or equal.
=IF(ROW(INDIRECT($D$3))>=ROW(),PERCENTRANK.INC($C$6:INDIRECT($D$3),C6))

Using COUNTIF, OFFSET, MATCH in Excel

I keep getting an error around this certain part of my COUNTIF function and cannot find out why. I believe it's cause the Offset function won't output a range. It seems to work fine if I manually put a range, but that isn't an option.
How do I get a range as an output using Match?
=COUNTIFS(OFFSET(Sheet2!$A$1,0,MATCH(I$1,Sheet2!1:1,0)),"*Accountable*")
I think you want to count "Accountable" from $A$1 until the found match, so you are trying to "expand" the cell A1 by as many cells. The parameter to enlarge the number of columns in the OFFSET function is parameter 5. Try this:
=COUNTIFS(OFFSET(Sheet2!$A$1,0,0,1,MATCH(I$1,Sheet2!1:1,0)),"Accountable")
' ^^^
You could use INDEX to achieve the same. (sometimes preferred for its non-volatility):
=COUNTIFS(Sheet2!$A$1:INDEX(Sheet2!1:1,MATCH(I$1,Sheet2!1:1,0)),"Accountable")
Solved:
A.S.H's tip on keeping the ranges the same solved most of it.
The second bit I was running into was just a miscalculation of columns.
It needed to be the match function and then minus 1 column.

Use of ROW() or COLUMN() in OFFSET(...) generating #N/A! error

I want to have a cell at the top of a column of data which uses a worksheet function to record the total number of cells below it which contain data. There are no gaps in the column, so I figure I don’t need to use COUNTA, it would be more efficient to find the first blank cell. To this end I have the following function in cell R12:
=MATCH(TRUE,INDEX(ISBLANK(OFFSET($R$12,1,0,1000,1)),0),0)-1
This worked fine until I tried to use a named reference cell to define the resized range a bit more flexibly… replacing the above with
=MATCH(TRUE,INDEX(ISBLANK(OFFSET($R$12,1,0,ROW(last_cell)-ROW(),1)),0),0)-1
gives #N/A! in the cell. As a formula =ROW(last_cell)-ROW() works fine on its own so it’s a puzzle to me why it doesn’t work in the compound formula… even replacing a 1 in the OFFSET parameters with ROW(A1) throws an error.
I can work round it, but this behaviour is really annoying! Can anyone shed any light on this?
The problem you are having is that the OFFSET function is expecting a long integer as its [height] parameter and you are shoving an array of integers at it. Yes, there is only one integer in the array but it is still an array and OFFSET is jumping ship at the first sign of potential trouble. If you evaluate the formula as suggested by Grade 'Eh' Bacon above, you will see that the result of that simple math subtraction is wrapped in braces (e.g. { and } ). You need to remove any indication that the [height] parameter is being fed an array or OFFSET will keep choking.
=MATCH(TRUE,INDEX(ISBLANK(OFFSET($R$12, 1, 0, MIN(ROW(last_cell)-ROW()), 1)),0),0)-1
There are any number of basic Excel worksheet functions that can take an array of 1 and turn it into an integer. I've used the MIN function. MAX, SUM, AVERAGE, etc. would all work. They take an array of numbers and return a single integer, even if that array of numbers has only one number.
On a related topic, I find it admirable that you are trying to reduce the calculation cycles in your workbook but you are missing one important consideration. The first thing you should do is throw out the OFFSET function altogether.
=MATCH(TRUE,INDEX(ISBLANK($R$12:INDEX($R:$R, ROW(last_cell)+1)), , ), 0)-1
OFFSET is a volatile formula that recalculates whenever anything in the workbook changes. Opting for the INDEX function equivalent takes the formula out of volatile mode and it will only recalculate when something that affects its outcome changes.
You may be interested in the way OFFSET erroneously treats floating point errors. See OFFSET_Floating_Point_Error for more on that.
Having had a chance to play around a bit, I'm still confused!
OFFSET itself doesn't seem to have a problem accepting the return values of ROW and COLUMN as parameters. To use a trivial example, this formula works:
=COUNTBLANK(OFFSET($R$12,ROW(1)+1,0,ROW(R20)-COLUMN(),1))
Trying different ways of eliminating OFFSET from the expression, I came up with:
=MATCH(TRUE,INDEX(ISBLANK(INDIRECT(ADDRESS(13,18)&":"&ADDRESS(1012,18))),0),0)-1
Which works, at the cost of swapping OFFSET for INDIRECT (which I'm hoping is the lesser of 2 evils!) However I would prefer to use:
=MATCH(TRUE,INDEX(ISBLANK(INDIRECT(ADDRESS(ROW()+1,COLUMN())&":"&ADDRESS(ROW(last_cell),COLUMN()))),0),0)-1
Which doesn't work, giving #N/A! again, as does changing any of the explicit integers to ROW or COLUMN expressions.
Individually, I've tried OFFSET, INDEX, ISBLANK and MATCH with ROW and COLUMN expressions and they all seem to work, so it seems to be something about using them in compound formulae which is throwing the error.

Using a Dynamic Named Range inside a Sum Formula

=SUM(IF(('Old Data'!$A$2:$A$10000=Tracking!A9)*('Old Data'!$B$2:$B$10000=$E$7)*('Old Data'!$D$2:$D$10000>$B$5)*('Old Data'!$D$2:$D$10000<$C$5),IF('Old Data'!$E$2:$E$10000-'Old Data'!$D$2:$D$10000<"4:00"+0,0.5,NETWORKDAYS('Old Data'!$D$2:$D$10000+0,'Old Data'!$E$2:$E$10000+0))))
is my current code. I created a defined name Total
Total = =COUNTA('Old Data'!$C:$C)
Everywhere that I have 10,000 I'd like to return the value of Total. I've tried simply replacing 10000 with Total, tryed using the + built in formula creator. I can't figure how to insert the value into my formula.
Any Ideas?
This seems like a formula question to me?
You can use INDIRECT See this example
If I have =Sum(A1:A10000) then in such a case I can use
=SUM(INDIRECT("A1:A"&total))
In my example total has been defined as =COUNTA('Old Data'!$A:$A)
Let me know if you still want a VBA solution.
SNAPSHOT
The best way to check it is to highlight the relevant section in the formula and click F9 to see how the values are calculated.

Excel, Specifying cell contents as a result of other cells

I don't use excel often, and I haven't really found a good solution to my problem. (which is probably really simple).
I would like to have a cell with a function in my spreadsheet that shows another cell value value that depends on yet another cell value.
Such as:
The Best Deal heading simply uses the formula
=MAX(D3,D1000)
But under Best Deal I would like to display the Name Test1 rather than the numeric value.
Another thing that would be nice to know, is if there is a way to know the maximum row with data in it. So rather than =MAX(D3,D1000) something like =MAX(D3,Max(RowCount_InD))
Obviously that function wouldn't work as I wrote it, but hopefully this pseudo code gives you an idea of what I mean. The purpose is that if more entries are added, it would be able to handle them.
I know this is possible, but I'm having some trouble. Hopefully I can get some help here.
Thanks!
The easiest way to do this is to use a combination of Index and Match. Match will find the position of the maximum value, and then Index will look in column A and return the data in that same position. So, your formula would be:
=INDEX(A$3:A$1000,MATCH(MAX(D$3:D$1000),D$3:D$1000,0))
Put that formula in F3. No hidden columns required.
Sorry, I missed the part about the expanding range. You can do that by using Count or CountA along with Offset. The new formula would be:
=INDEX(A3:OFFSET(A3,COUNTA(A:A)-1,0),MATCH(MAX(D3:OFFSET(D3,COUNT(D:D)-1,0)),D3:OFFSET(D3,COUNT(D:D)-1,0),0))
More complex, but it is basically the same except that it will expand as you add new values at the end.
There is only one 'simple' way I can think of this, but it requires hidden columns (sorry).
set E1 = A1 and fill down all the way (Basically you are making a copy of column A in column E but you are using a formula so it will always be the same)
Then under 'Best deal' - put this formula:
=VLOOKUP(MAX(D3,D1000),$D:$E,2,FALSE)
Then hide column E so it doesn't look like a mess. This way you do not need any fancy macro's and it will work everywhere because it is a normal formula.
"Another thing that would be nice to know, is if there is a way to know the maximum row with data in it. So rather than =MAX(D3,D1000) something like =MAX(D3,Max(RowCount_InD))"
This is a called a dynamic named range. Create a name for the ratio data, and set up the formula for the name range to be this:
=OFFSET($D$3, 0, 0, COUNTA($D$3:$D$1048576), 1)
More info here: http://www.ozgrid.com/Excel/DynamicRanges.htm
Then, assuming you name this named range ratio_data, your function could be referring to =MAX(ratio_data) in combination with index-match as suggested by #Tim Mayes. The range will expand automatically as you add more data.
=INDEX(A$3:A$1000,MATCH(MAX(ratio_data),ratio_data,0))
Ideally, you can replace the A3:A1000 by a dynamic named range as well.

Resources