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?
Related
For example I have this set of data below:
Header 1 Header 2
Mouse 5
Elephant 4
What I want to happen is for the word "Mouse" to repeat 5 times and the word "Elephant" to repeat 4 times from top to bottom in Column C.
The output will look something like this:
Header 1 Header 2 Header 3
Mouse 5 Mouse
Elephant 4 Mouse
Mouse
Mouse
Mouse
Elephant
Elephant
Elephant
Elephant
How to do this in Google Sheets?
Thank You
Try the below formula:
Assuming your data range is A2:B and you are entering the formula in C2, if not then you can change the range accordingly
=ARRAYFORMULA(TRIM(TRANSPOSE(SPLIT(QUERY(
REPT(A2:A&",", B2:B), ,999^99), ","))))
Supposing that your "Header 1" is in A1 and the rest of your posted sample is in A:B, place the following formula in C1 of an otherwise empty Column C:
=ArrayFormula({"Header 3"; QUERY(FLATTEN(SPLIT(FILTER(REPT(A2:A&"~",B2:B),A2:A<>""),"~",1,1)),"Select * WHERE Col1 Is Not Null")})
This formula will produce the header text (which you can change within the formula as you like) and all results.
REPT will repeat anything in A2:A (with a tilde appended to the end) B2:B times to form virtual single-cell strings.
FILTER will make sure only occupied rows are included in the REPT function.
SPLIT will split those repetitive strings into separate horizontal cells at those intermittent tildes.
FLATTEN will take all of the results of the SPLIT and form one column from them (spaces and all, since the number of cells per virtual row will differ depending on the requested number of repetitions).
QUERY will purge any empty rows that would have otherwise appeared in the FLATTEN results.
ArrayFormula is necessary because the formula is processing a range as opposed to a single row's data.
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. :)
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.
Hi so I'm trying to make a spreadsheet in Google Sheets that takes two numbers and subtracts them and then does it in the next row .
So example the formula in C1 would be "subtract(A1, B1)" in the first row. But then in the next row I would like it to change to "subtract(A2, B2)" and output in C2.
(Without having to go in each C cell and change the formula of course)
So how do I do that and also how do I apply a formula to multiple cells of a row (C1,C2,C3,C4,C5, etc....)
Just put =MINUS(A1,B1) into C1 and then copy it and paste it in the remain rows of column C and the spreadsheet automatically adjusts the row numbers for you.
#Cooper's Answer above is perfect. I'm just giving a alternative here using array formulas, because it's easy.
Put this in D2
=ARRAYFORMULA(MINUS ( B2:B, MULTIPLY( 2.5, QUOTIENT(C2:C,15))))
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.