Increment ROW, not COLUMN when dragging formula horizontally - google-sheets

I'd like to drag the formula
=if(and(AHTpivot!$A1=statusSheet!$A1, AHTpivot!$B1="wrap-up"),AHTpivot!$C1, "")
right to adjacent columns about 1,000 times. I only want statusSheet!$A1 to increase, and it needs to increase in rows instead of columns.
For instance, if the formula is in A1, and I drag it to B1, it should be in cell B2. [?]
=if(and(AHTpivot!$A1=statusSheet!$A2, AHTpivot!$B1="wrap-up"),AHTpivot!$C1, "")

Maybe:
=if(and(AHTPivot!$A1=indirect("StatusSheet!$A"&Column()),AHTPivot!$B1="wrap-up"),AHTPivot!$C1, "")

You could also use an array formula if you don't want to drag the formula.
=ARRAYFORMULA(IF(
(AHTpivot!$A1=INDIRECT("statusSheet!$A"&COLUMN(A1:AAA1))
* (AHTpivot!$B1="wrap-up")
,AHTpivot!$C1, "")
The * acts as an and.
Change AAA1 to the column reference you desire. Or, change to COLUMN(A1:1) if you want to go to the end of the sheet.
Credit to pnuts for the INDIRECT idea. :)

Related

ARRAYFORMULA with a range that changes from cell to cell

I have a list of items in column A. In column B I want to use an ARRAYFORMULA function that will bring the serial number of each item to appear - 1 next to the first item, 2 next to the second etc.
This formula works fine but breaks when there are blank rows:
=ARRAYFORMULA(IF(LEN(A2:A),ROW(A2:A)-1,""))
This formula works nice but I need to drag it which I don't want to do. This is why I want it as an ARRAYFORMULA (note that I fix the range to always start from A$1 so only the range changes in size as I drag it further down).
=IF(LEN(A2),COUNTA(A$1:A2),"")
What I need is basically something that will work like the 2nd formula but with an ARRAYFORMULA.
Here's a spreadsheet to make it clearer (col A is the list, col C is function 1 and col D is function 2):
https://docs.google.com/spreadsheets/d/17qVGwvFJVrxdwkgmVQatH3Urpjl0_xB8EGqUsPVIwl8/edit?usp=sharing
In F2 I entered
=ArrayFormula(if(len(A2:A), countifs(A2:A, "<>", row(A2:A), "<="&row(A2:A)),))
See if that works for you?

Sum of cells containing a formula in google sheets

I want the sum of values in a column. However I wish to ignore cells which do not contain a formula. I tried
=SUMIF(A1:A10, ISFORMULA(A1:A10))
But that did not work
if its a small range you can do:
=SUM(FILTER(A1:A10, {ISFORMULA(A1); ISFORMULA(A2); ISFORMULA(A3);
ISFORMULA(A4); ISFORMULA(A5); ISFORMULA(A6);
ISFORMULA(A7); ISFORMULA(A8); ISFORMULA(A9); ISFORMULA(A10)})
This way might work for you.
I added a column with the following formula, which unfortunately also doesn't work as an arrayformula. But if you put this at the top of your column, beside the one you want to sum, and double click the "drag down" blue square on the bottom right corner of the cell, it will fill all the way down, provided you have no blank rows. Dragging down also works obviously.
=IFNA(FORMULATEXT(A1),0)
This creates a column of zeroes and text formulas, which you can use as a filter for your SUMIF formula, as follows: (assumes data column is A1:A30, helper column is B1:B30. SUMIF is in C1)
=SUMIF(B1:B30,"=0",A1:A30)
Let me know if this is useful, or not.

How to write a formula that would work in different rows?

I'm trying to make a Google spreadsheet where I want the sum of the values in the row to appear in the AH cell of that row.
The row would be populated with letters like L or X and I'm using COUNTIF to give value to the alphabet characters.
For example,
=COUNTIF(C4:AG4,"X")*9 + COUNTIF(C4:AG4,"L")*12
How can I write the range such that it looks at cells C through AG from the same row the formula is in rather than change it for every row?
You don't need to change the formula, if you write that formula in one cell and then you drag the little square at the bottom right of the cell, excel will automatically change the row number
Just copy downwards:
As you see, the row index changed to 5 automatically.

Google Sheet Dynamic Sum

I am using google sheets to make a spread sheet and do some simple math, I figured how to do the summing but the problem is that I have about 180 rows of data and want to avoid, if possible, the need to make a formula for every single pair of data. Here is the simple code that I have:
=SUM(AG4:AG5)
So I am writing this code in this case in AH4 and is always the same relative placement to the values I want to add. I want the sum of the two numbers one column to the left and the current row and a row under that. Is there any way to make it so that the same formula can be used over and over instead of typing each one out. Maybe some way to make the formula look one column to the left take that number and add it to the cell one column to the left and one row down?
Thanks for any help you can provide.
You can use the ARRAYFORMULA function to apply a formula to multiple rows. It does not like some functions, though, and SUM() is one of them. So we need to use a different method to add the numbers. In this case, we just use AG4 + AG5. To apply the formula to all the rows in the spreadsheet we do a little more. Here is the formula, which would be placed in cell AG3 provided that is where the formula should start adding items.
=ARRAYFORMULA( IF( ISBLANK( AG3:AG),, AG2:AG + AG3:AG))
The IF ISBLANK AG3:AG) causes the formula to be applied to every row from row 3 to the last row in the sheet. ISBLANK will return FALSE on any row we want to work on so we provide nothing to teh TRUE portion of the IF statement. Note that I did not put "" in for the TRUE portion as that actually places a value in the row and can cause problems with other formulas. Since we are placing this in cell AG3 the addition will increment adding the row above to the current row.
EDIT from Comments
Placing this in cell AH2 will get you what you want:
=ARRAYFORMULA( IF( ISBLANK( AG2:AG),, IF(iseven( ROW(AG2:AG)),AG2:AG + AG3:AG,)))
Taking it a step farther, placing this in cell AH1 will label the header row for you and keep the formula out of the data rows. This has the advantage of allowing rows to be inserted above row 2.
=ARRAYFORMULA( IF(ROW(AH1:AH) = 1, "Total", IF( ISBLANK( AG1:AG),, IF(iseven( ROW(AG1:AG)),AG1:AG + AG2:AG,))))
The explanation is similar to above, only minor changes were made.
NOTE: The rest of column AH (below the formula) should not have any other manually entered data, so you will have to delete your formulas.

Insert formula through google sheet column

lets say I have a column of URLs in A, I would like to have a script that would insert a formula into the next column over so that it would look like the attached image.
I know how to insert a formula into a single cell through script, but unsure of how to get it down the entire column relative to the cell to the left.
You can use array formula like this:
=ARRAYFORMULA(IMAGE(A2:A))
or you can wrap it in an if statement to only pull in the images where there is a valid url present with:
=ARRAYFORMULA(IF(ISURL(A2:A),IMAGE(A2:A),))
ArrayFormula is good solution. I prefer limiting the used range by it's size. If your data has no blanks, you could also use this formula:
=ARRAYFORMULA(IMAGE(OFFSET(A2,,,COUNTA(A:A)))
Paste it in cell B2.
offset + counta will give range A2:A6 in your case.

Resources