I was originally building a formula to count how many cells were being filled in on a sheet different from the one that I was working on. I chose a set of blank cells on Sheet1 with the following formula:
=COUNTA(ADDRESS(3,5,4,1,"Sheet1") & ":" & ADDRESS(4,12,4,1))
The result was 1 for a set of blank cells. The equivalent formula - =COUNTA(Sheet1!E3:L4) - returns the correct answer of 0.
Why don't I get the same result?
Background: in the actual formula that I was using, I'd replaced the 3 & 4 in the ADDRESS function with a ROW() calculation to choose 2 rows at a time on Sheet1 1 row on Sheet2. I was testing the ADDRESS function for use by hardcoding the row addresses.
ADDRESS creates a string, not an actual Cell Reference. So, =ADDRESS(3,5,4,1,"Sheet1") is ="Sheet1!E3", not =Sheet1!E3.
To convert a String to a Cell Reference, use the INDIRECT function: =INDIRECT("A1") is the same as =A1.
Stick it together, and...
=COUNTA(INDIRECT(ADDRESS(3,5,4,1,"Sheet1") & ":" & ADDRESS(4,12,4,1)))
(I hope you are going to change some of those 'magic numbers' to functions or cell-reference, otherwise you could just use =COUNTA(Sheet1!E3:L4) instead!)
Related
I have a spreadsheet with multiple sheets.
Sheet A is generated from a template, and it is where users will enter in data to be formatted into a report; it will be deleted after that report is submitted.
As people enter info into Column A of Sheet A, they don't have to enter client information if we already have them entered in this spreadsheet, but otherwise they need to go over to Sheet B and enter it in.
To make it easier for them (so they don't have to check every time, or go back and enter info later after getting an error generating the report), I have used conditional formatting. The way it works is, column Z is set up as a helper column, and uses a "COUNTIF" function to check if the client ID in Sheet A, Column A is found in Sheet B, Column C. Sheet A Column Z returns 0 or 1 (or, theoretically, more than one if we had duplicates), and then Sheet A column A has conditional formatting based on Column Z's value-- if the client is already in, the cell for client ID turns green after they type it; if not, it turns red.
It works great! However, I am adding scripts to these sheets, and looping through them. This helper column is filled from Z1 to Z1000, which means I can't use sheet.maxRow() to get the last row.
I see plenty of workarounds on the script side, but I was wondering if anyone has a clever way to input a value into the helper column Z ONLY IF the corresponding cell (same row) in column A has a value using spreadsheet formulas.
I suspect that an array formula with a filter might do it, but I have little experience with either and can't get anything to work out.
Thanks for your help!
You can use this expression with INDEX, MAX and ROW to make an ARRAYFORMULA only expandable until the last cell with value in column:
A2:INDEX(A2:A,MAX(ROW(A2:A)*(A2:A<>"")))
It will go from A2 to the maximum number of row in A in which A is different than null (that's why both conditions are multiplied).
Then you can set a formula like this in Z2 (check the ranges in case something is not right from reading your text, and delete all other formulas in Z too in case you weren't using an arrayformula already):
=BYROW(A2:INDEX(A2:A,MAX(ROW(A2:A)*(A2:A<>""))),LAMBDA(each,IF(each="","",COUNTIF('Sheet B'!C:C,each))))
I am looking to create a formula that enables me to search a set of data for an 8 digit number. I have attached my testing sheet.
In column B is the stock numbers I need to find within a set of data.
In column E is the full list to be checked against, however, within any one cell, you can have several different 8 digit stock numbers.
In my test sheet, I have found that a vlookup only searches for the first stock number and not all the stock numbers within that cell. I have attempted an index match formula combined with a transpose split however none of these has enabled me to properly search my data set.
=ARRAYFORMULA(VLOOKUP(B2:B,$E$2:$E,1,0))
then
=INDEX($E$2:$E$1139,(MATCH(B2,TRANSPOSE(SPLIT($E$2:$E,";, ")))))
The data can be separated within the cell with either spaces or "," or ";"
You should be able to make a copy of my test sheet using this link:
https://docs.google.com/spreadsheets/d/1UckPZw6tWBw0H13p79N94IqV2EFyfhYNyEhmLecr3XM/copy#gid=55962883
Hope you can help.
try:
=FILTER(E:E, REGEXMATCH(E:E&"", TEXTJOIN("|", 1, B2:B)))
update:
to get true/false use:
=INDEX(REGEXMATCH(E2:E&"", TEXTJOIN("|", 1, B2:B)))
or if you want to return match or N/A use:
=INDEX(IF(REGEXMATCH(E2:E&"", TEXTJOIN("|", 1, B2:B)), E2:E, ISNA()))
In this sheet, I've the below input data:
As seen, the courses are separated by /
I want to display the same in the format below, where each line shows one course only, with the data of the student repeated:
I know using =split(C3," / ",true,true) can split the courses into 2 columns at the same row, but I need them in the same column, so I tried =TRANSPOSE(split(C3," / ",true,true)) that is working fine for the first line only, but it fail with using ARRAYFORMULA.
Any thought? I'm opened for any potential solution, formula or script or any other.
UPDATE
I tried this trick, creating a new column showing number of courses for each student as =ArrayFormula(LEN(REGEXREPLACE(C11:C13, "[^/]", ""))+1)
Then using Rep to repeat each row based on the number of courses =arrayformula({transpose(split(concatenate(rept(B11:B13 & ",",D11:D13)),",",false,true)),transpose(split(concatenate(REPT(C11:C13 & ",",D11:D13)),",",false,true))}) then ended up with:
But here, I've the courses still joint together, how can i split them!
I've added two sheets to your sample spreadsheet. "Sheet2" is a cleanup of your testing sheet, "Sheet1." The other sheet ("Erik Help") references Sheet2, not Sheet1, and contains the following formula in cell A1:
=ArrayFormula({"Student ID","Student Name","Course";SUBSTITUTE(SPLIT(QUERY(FLATTEN(SPLIT(FILTER(SUBSTITUTE("/ "&Sheet2!C3:C,"/","/ "&Sheet2!A3:A&"zzz~"&Sheet2!B3:B&"~"),Sheet2!A3:A<>""),"/")),"Select * WHERE Col1 Is Not Null"),"~"),"zzz","")})
This one array formula produces all headers and results.
A virtual array is formed between the curly brackets { }. Headers are introduced first followed by a semicolon, which means "bump down one row to continue." The header titles can be changed as you like.
How It Works:
An addition "/ " is concatenated to the front of every non-blank entry in Sheet2!C2:C. Then SUBSTITUTE replaces every one of these forward slashes with Col A data, "zzz~", Col B data and "~". The tildes (~) will be used later by the outer SPLIT. The "zzz" is added to make sure that ID numbers are converted to text so that they hold formatting throughout the processing and don't turn into real numbers; later, the outer SUBSTITUTE will replace those with null (i.e., get rid of the 'zzz').
Once the initial concatenations are complete, they are SPLIT at the forward slash and then FLATTENed into one column. QUERY removes any blank rows in this virtual array so far. The remaining results are again SPLIT at the tilde. Finally, that outer SUBSTITUTE removes the temporary instances of 'zzz'.
I also added a custom CF formula for the alternating color banding on alternate rows.
You can try this one:
Formula:
=ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(C3:C5, "/"))="",,
A3:A5&"×"&B3:B5&"×"&SPLIT(C3:C5, "/"))), "×"),
"where Col3 is not null")))
Output:
Reference:
How to transpose & split multiple columns and repeat specific cells in a column
I want to calculate the quotient of the cells in E and D rows, the logic is if both cells contains valid values then calculate otherwise do not do anything.
So far this is my formula:
={"OR (Open Rate)";ARRAYFORMULA(IFERROR(E2:E/D2:D))}
This works fine as it doesn't add value to the cell. But when I use the getLastRow() function on script editor, I get almost the 1000th cell on my empty sheet.
I suspect that the formula I am using is inserting a space or falsey values on each cell. How can I leave the cell blank if it doesn't meet my logic expression?
={"OR (Open Rate)";ARRAYFORMULA(IFERROR(E2:INDEX(E2:E,COUNTA(E2:E))/D2:INDEX(D2:D,COUNTA(E2:E))))}
I have a spreadsheet with roughly 750 part numbers and costs on it. I need to add $2 to each cost (not total the whole column). The range would be something like D1:D628 and I've tried using =SUM but either I'm doing it wrong or it isn't possible.
I initially tried =SUM(D1:D628+2) and got a circular reference warning, I've tried variations of the formula and keep getting errors even after removing the circular reference. I also tried the following VBA module insert:
Sub Add2Formula()
' Add 2
For Each c In Selection
c.Activate
ActiveCell.FormulaR1C1 = "= " & ActiveCell.Formula & "+2"
Next c
End Sub
If you just want to add 2 to a range of numbers (not formulas) then
enter the number 2 in a blank cell somewhere
copy it
Select the cells you want to add 2 to, and then select paste special, choose ADD as the operation option.
The following formula should work
{=SUM(D1:D628+2)}
Leave out the curly braces but press CTRL+SHIFT+ENTER to enter the function (rather than just ENTER)
EDIT: explanation
by pressing CTRL+SHIFT+ENTER excel treats the formula as an array, and loops through each cell individually adding 2 and then summing