How to use variable range in Google Sheets? - google-sheets

Currently I have such formula:
COUNTIFS(B3:B36,"16",E3:E36,"01")
Would it be possible to turn these ranges B3:B36 and E3:E36 into variables, like B'start_cell_value':B'stop_cell_value'.
The whole thing would look like:
=COUNTIFS(B'start_cell_value':B'stop_cell_value',"16",E'start_cell_value':E'stop_cell_value',"01")
start_cell_value and stop_cell_value are just some numbers stored in a separate cell. This would help, since changing numbers in those cells only would also change everything in the formula and that's exactly what I want.
I have tried to combine a numeric value from other cells with a letter to make a valid cell name but it doesn't seem to work or it just throws a reference error.
Any ideas would be appreciated.

If you have the start_cell_value in cell A1 and the stop_cell_value in A2 then try this formula:
=COUNTIFS(INDIRECT("B"&A1&":B"&A2),"16",INDIRECT("E"&A1&":E"&A2),"01")

with Named Ranges you can have it even exact:
=COUNTIFS(INDIRECT("B"&start_cell_value&":B"&stop_cell_value), "16",
INDIRECT("E"&start_cell_value&":E"&stop_cell_value), "01")
=COUNTIFS(INDIRECT("B"&A1&":B"&A2), "16",
INDIRECT("E"&A1&":E"&A2), "01")

Related

Can a condition be referenced as a key in match?

I’d like to find the lowest number in a column that is more/less than a given cell. Could I do this with MATCH? If so, how do I put in a conditional component?
I’ve tried >(cell name) and a few other things, none of which worked.
try a custom formula under conditional formatting:
=(A1<B$1)*(A1=MIN(A:A))
or:
=A1=MIN(FILTER(A:A, A:A<B$1))
where column A are numbers and B1 is cell with your value

Troubleshooting formula with array - array arguments are of different size to EQ

In Google Sheets, I have a formula that displays the value of an item in a row if one of its cells contains any of the values listed in a different sheet. It looks like this:
=ARRAYFORMULA(IF(OR(L2 = ZRSKUs!$A$1:$Z$12005), O2, "0"))
If L2 contains any of the values in sheet ZRSKUs, this formula displays the value of the item, which is held in O2. If I drag the formula down it produces the value of every column and I can then get a SUM of this column. I wanted a way to do this without having to drag the formula down every single row (this spreadsheet has about 20,000 rows so it takes a long time to do). I also wanted the formula to add it up too, so it is all done in one cell.
I tried editing the formula to do this, and this is what I came up with:
=ARRAYFORMULA(SUM(IF(OR($L3:$L = ZRSKUs!$A$1:$A$500), $O3:$O, "0")))
However, this gives me an "Array arguments to EQ are of different size" error. I tried adjusting the number of rows in the ZRSKUs sheets so it had the exact same number as my other sheet, but this made no difference.
I'm not sure what's going wrong, so any help or advice would be greatly appreciated!
You get the error because that is not a well-formed array formula, as $L3:$L and ZRSKUs!$A$1:$A$500 are not equal in length. We could rectify this by using another function for the lookup, in this case, MATCH:
=ARRAYFORMULA(SUM(IF(ISNA(MATCH($L$1:$L, ZRSKUs!$A$1:$A$500, 0)), 0, $O$1:$O)))

multiple if conditions nested with a concatenate - Google Sheets

I have a formula as follows which I'm using for a scheduling system within Google Sheets:
=IF(B2="","",(CONCATENATE($B$1&" "&B2&CHAR(10)&$C$1&" "&C2&CHAR(10)&$D$1&" "&D2&CHAR(10)&$E$1&" " &E2&CHAR(10)&$F$1&" " &F2&CHAR(10)&$G$1&" " &G2)))
currently my formula works b2 has a value inside it which is great, what I want however, is for the formula only to show if one value is inside either.
B2, C2, D2, E2, F2 or G2.
so if c2 has a value I want the formula to parse.
I've tried
=IF(B2,C2,E2) etc with no luck.
I've also tried:
=IF(OR(B2="",C2="") which parsed the formula but kept it visible even with no data.
Reason for this is that I pull these fields into a master schedule and I only want it to show when one of the fields is populated, if that makes sense? otherwise the schedule will look far to busy.
https://docs.google.com/spreadsheets/d/1KE3VOI43M4-QlWB0EZldCqR73d3RHDnRnUNlv1MqLMo/edit?usp=sharing
Document for you guys.
Cheers!
If your goal is to show a formula when any of a given range of cells is not empty (and display nothing if they are all empty), you can simplify your condition check by first joining all ranges, and then comparing to the empty string:
=IF(JOIN("", B2:G2)="", "", "Your Formula")
You need to use AND() instead of OR().
=IF(AND(B2="", C2=""), "", "Formula")
Also, although this makes the formulas longer, I do prefer to use a combination of IFERROR(), ISBLANK(), and NA(). I prefer this because a blank cell is not the same as one with an empty string in it. So my preferred way of writing the above would actually be:
=IFERROR(IF(AND(ISBLANK(B2), ISBLANK(C2)), NA(), "Formula"))
just another solution I came across which I thought was much better than my own and made the data above a little tidier.
=IF(A2<>"",CONCATENATE(IF(B2<>"",$B$1&": "&B2&CHAR(10),),
IF(C2<>"",$C$1&": "&C2&IF(OR(D2<>"",E2<>"",F2<>"",G2<>""),CHAR(10),),),
Essentially this will populate only whats selected instead of populating all the fields in headers and then populating the scheduled work stream.

How to return the cell next to the cell that contains a string in Google Sheets?

So say I have a google spreadsheet where:
A1 contains a string,
and I have a bunch of cells in Column D that contain strings.
There is a cell in column D that matches A1. Say it is D5.
My goal then, is to make a function that returns E5.
I tried using MATCH, but that returns the number in the array, rather than the cell address. Even if it did return the cell address, I'm not sure how I would use it to find the cell next to it. Optimally, I would like this address to be returned in a way that I can input into another function. So how can I do this?
Please tell me if I can make this question more clear in any way. I'm very tired right now, so it might be worded weirdly.
Thanks in advance!
VLOOKUP() is exactly what you need, if you need the cell value of E5.
=vlookup(A1, D:E, 2, 0)
If you need the cell's address, you are probably thinking about your problem wrong - what is it exactly you want to do with the cell address?
There are two functions, that will be handy in this case:
if you want to get value from E5 then use offset
if you need to get "E5" as string, then use address function.
Also if you have an address like "E5" you may get the value of E5 with indirect function.

Google spreadsheet, passing parameter

Okay, I'm an huge noob with that kind of stuff, and I don't really know where to begin with. Google help is somehow not enough :/.
I want to make a conditionnal count on a single column :
COUNTIF(A1:A10, "3")
It will return the number of 3 in the cells from A1 to A10. Now the problem is, there can be multiples values in each cell formatted like this : "1; 3; 5". I can easily match this using regex :
B1 = REGEXEXTRACT(A1,"3")
Then repeat and sum on the second column. Now, how can I do this using a single formula?
COUNTIF(A1:A10, REGEXEXTRACT(A1:A10,"3"))
This doesn't work because regexextract take as an input a single cell. I would like to tell it to use the same cell than in the countif, but I have no clue on how to achieve this.
you can have regextract working on an array. E.g.:
=ArrayFormula(sum(--regexmatch(A2:A&"", "3")))
should count all threes (either single or in cells with multiple values), but in case you have multiple threes in one cell, you may need to use something like this:
=ARRAYFORMULA(sum(len(A:A)-len(SUBSTITUTE(A:A,"3","")))/len("3"))
This should work:
=COUNTIF(SPLIT(JOIN(";",A:A),";"),"3")

Resources