Copying Formulas in Google Sheet - google-sheets

I have a requirement please, I want to copy formulas from one cell to another Example:
I have 4 sheets in my spreadsheet, E.g. Sheet1, Sheet2, Sheet3 & Sheet4 now let’s assume that in the 1st sheet I write a formula in A7 Cell
=If(G7=1,"True","False")
where G7 has either 1 or 0.
I want the same to get copied in 2nd, 3rd and 4th sheet in A7 Cell.
I know I can copy and paste them however in the real use case the formula is called so many times at different places that any change in the formula makes it really difficult to copy them to all the places.
So I want that I will change the formula in Sheet1 ONLY and the change will get replicated in the other 3 Sheets.
I have tried creating a custom function however since it’s a lot of data and so many calls to the function, makes it really slow. I don’t know what could be the best option for my problem. Hence need your help, please.
Any help would be really appreciated.

that's not possible but you can do this:
put your formula in G7
copypaste this formula on 1000 different locations (where you need them)
then press CTRL + H and:

You can't 'send' a formula with a formula, only 'fetch' its result, so you would need something like Google Apps Script (and questions about that here should routinely show an attempt at writing the code).

Related

how can I write a formula that uses a cell's contents when building a range reference to the name of another sheet?

I have a large Google Sheets spreadsheet that has individual sheets for financial statements of activity for multiple years. I want to reference particular columns of those in other sheets, and I've successfully figured out how to do that with an HLOOKUP function. However, because I want to do this for multiple years, I'd like that HLOOKUP function to pick up the name of the sheet to reference from its column header. Right now, I'm hard-coding it like this—you can see the HLOOKUP range refers to cells in the "2021 Overall" sheet. The hard-coded approach works but makes adding a new year tedious. Ideally, the HLOOKUP formula would read the contents of its column header cell to determine which year it is.
As best I can tell, the solution is to use INDIRECT, but I can't figure out any way to build the formulate with INDIRECT and not get an error. For instance, this seemed like it should work. As you can see, I have 2021 in cell D4, and my INDIRECT statement is referencing that and building the rest of the range.
I've also tried using INDIRECT with an explicit CONCATENATE, with no more success.
Any ideas for how to look up that D4 cell and slide it into the HLOOKUP range?
Thank you!
Try to remove the "'"& before D4 and the ' after the Overall.
Your formula should look like this:
=IFERROR(HLOOKUP($A$2,INDIRECT(F4 &" Overall!$A$5:$X$150", Utility!$A10, FALSE)))
With Nikko's nudges in the right direction, I eventually figured out the right format. This allows the formula to work in multiple sheets and to be filled right (for more years) and down (for more classes).
=IFERROR(HLOOKUP($A$2,INDIRECT("'"D$4&" Overall'!$A$5:$X$150"), Utility!$A3, FALSE))
Note that if you try to replicate this, you may need to type the formula out from scratch—I had a problem where pasting it in didn't work. Once I'd retyped it and Google Sheets acknowledged it, it worked from then on in the spreadsheet, even when pasted from sheet to sheet.

Google sheets, two-sheet dependent conditional formatting

My problem is probably trivial ... However, I was looking for similar problems and their solutions either do not work for me or I can not apply them.
I have 2 sheets - SheetA and SheetB. They are identical. I want to select every cell in SheetA that is no longer identical to Sheet B.
I was able to use (found here on Stack Overflow) such a function in conditional formatting:
= A1 <> INDIRECT ("SheetB! A" & ROW ())
It works if the range is column A. I know that I can apply this function to each column separately, but there is certainly a way that I can apply the same formula to the whole worksheet.
Will there be anyone who can show me the correct formula?
Edit: I tried to use above formula to every column... And my file become to work very slow... So whoever wants to do the same... think again.
After some tries I decided to move everything from SheetB to SheetA. I paste it a 1000 rows under data of Sheet A. Works fine without "indirect" function. No slow downs. It is not a perfect solution but it works.
But even after my problem is solved different way, I would like to know what is the correct formula for my problem... it might be useful for the future with smaller amount of data.
Solved ;)
You should be able to use the Address function to get the address of the current cell from its row and column:
=A1<>indirect("sheetB!"&address(row(),column()))
or for case-sensitive match:
=not(exact(A1,indirect("sheetB!"&address(row(),column()))))

Using a Named Range to identify worksheets to use a SUMIFS on a to add an array of data

Below is a sample of the Google Sheet I'm working on:
https://docs.google.com/spreadsheets/d/1LDsfn_FMdUSfuFZAyuXf5gdlOSN9yLqhT1RY8aX7Nfs/edit?usp=sharing
On the spreadsheet Team Totals, I'm trying to calculate all the sales based on the date, the type of sale, and the program type starting from Row 27.
The problem I have run into is that the Named Range, Consultants, only pulls the data from the first cell of the Named range (Octo). What I want is for a formula that will pull the data of the selected range from each entry in the named range and sum them together.
For reference, I put what the proper values should be starting from Row 33.
The closest example I have seen was from this website: https://www.got-it.ai/solutions/excel-chat/excel-tutorial/sumif/sumif-across-multiple-sheets
However, I get the same problem that only the first cell in the named range gets pulled.
I feel like I'm missing something simple, but I have been bouncing it around my head for hours and can't figure it out. Any help is greatly appreciated.
So after trying to figure out a way not to use an iterative process, I folded and did this:
=arrayformula(SUMIFS(INDIRECT("'"&$B$4&"'!F6:F100"),INDIRECT("'"&$B$4&"'!D6:D100"),$B$2,INDIRECT("'"&$B$4&"'!E6:E100"),E$27,INDIRECT("'"&$B$4&"'!A6:A100"),$A41)+
SUMIFS(INDIRECT("'"&$B$5&"'!F6:F100"),INDIRECT("'"&$B$5&"'!D6:D100"),$B$2,INDIRECT("'"&$B$5&"'!E6:E100"),E$27,INDIRECT("'"&$B$5&"'!A6:A100"),$A41)+
SUMIFS(INDIRECT("'"&$B$6&"'!F6:F100"),INDIRECT("'"&$B$6&"'!D6:D100"),$B$2,INDIRECT("'"&$B$6&"'!E6:E100"),E$27,INDIRECT("'"&$B$6&"'!A6:A100"),$A41)+
SUMIFS(INDIRECT("'"&$B$7&"'!F6:F100"),INDIRECT("'"&$B$7&"'!D6:D100"),$B$2,INDIRECT("'"&$B$7&"'!E6:E100"),E$27,INDIRECT("'"&$B$7&"'!A6:A100"),$A41)+
SUMIFS(INDIRECT("'"&$B$8&"'!F6:F100"),INDIRECT("'"&$B$8&"'!D6:D100"),$B$2,INDIRECT("'"&$B$8&"'!E6:E100"),E$27,INDIRECT("'"&$B$8&"'!A6:A100"),$A41)+
SUMIFS(INDIRECT("'"&$B$9&"'!F6:F100"),INDIRECT("'"&$B$9&"'!D6:D100"),$B$2,INDIRECT("'"&$B$9&"'!E6:E100"),E$27,INDIRECT("'"&$B$9&"'!A6:A100"),$A41))
This formula allows me to cut and paste it to various cells easily, and does the job I need it to, while still using the indirect reference so I can change names without breaking the formula (granted I change the worksheet name as well).
I will need to edit this to include all possible worksheet amounts I can forsee, but once it's done, I won't have to tinker with names anymore.
I'm not happy with this answer, as it creates a really long and ugly formula, essentially repeating the same formula 20 times, but it does work. I feel like there should be an easy function that would be able to do this.
This will return Total sales:
=if(isna(ArrayFormula(QUERY({Lo!$A$5:$F; Tulio!$A$5:$F;Ya!$A$5:$F; Miguel!$A$5:$F;Kevin!$A$5:$F; Octo!$A$5:$F}, "select sum(Col6) where Col1=date '"&TEXT(A28,"yyyy-mm-dd")&"' label sum(Col6) ''",0)))=TRUE,0,ArrayFormula(QUERY({Lo!$A$5:$F; Tulio!$A$5:$F;Ya!$A$5:$F; Miguel!$A$5:$F;Kevin!$A$5:$F; Octo!$A$5:$F}, "select sum(Col6) where Col1=date '"&TEXT(A28,"yyyy-mm-dd")&"' label sum(Col6) ''",0)))
BTW, I get Total sales of $0, $615.50 and $2,498.00
The best way to pull data from a lot of unknown tab names without a script is to actually CREATE the tab names beforehand. On your sheet it looks like you're anticipating/making space for 21 employees. If I were you, I would just create 15 more tabs named Temp7,Temp8,Temp9... etc. Then you can just "hide" those tabs. Then a formula can be built in your totals section that will easily stack all the tabs up using an array literal and a QUERY( { } ) to add up the totals for you without all this INDIRECT() nonsense that you have been going through to pull from the individual tab names.
Would pre-adding tab names be something you were interested in if I could show you the formulas to make the totals easy to calculate?

Using IMPORTRANGE, INDIRECT, and CONCATENATE together

I have a sheet that pulls numbers from several different sheets to amalgamate numbers. Each week, a new sheet is added to the source files, all with the same name. I'd like to update the amalgamated sheet by changing one cell instead of many.
When the tab is located in the same Google sheet, this is easily done with INDIRECT.
Right now, the formula in the amalgamated sheet is:
=IMPORTRANGE(M4, "Aug29!$F$2")
That formula is on each line to pull from several different sheets:
=IMPORTRANGE(M5, "Aug29!$F$2")
=IMPORTRANGE(M6, "Aug29!$F$2")
and so on.
Each week, the "Aug29" changes to the new date - "Sep5", "Sep12", etc.
What I'd like to do is use INDIRECT to pull that part of the equation in (from cell Z1) so that I don't have to update each formula.
I was thinking I could use CONCATENATE to create the "Aug29!$F$2" portion of the formula with INDIRECT:
=IMPORTRANGE(M4, CONCATENATE(INDIRECT(Z1), "!$F$2"))
The problem is, the IMPORTRANGE formula requires quotations around the range string, and I can't figure out how to add them.
Weird problem, I'm sure, but wondering if there's anyone with a solution?
Short answer
Use =IMPORTRANGE(M4, CONCATENATE(Z1, "!$F$2")) or =IMPORTRANGE(M4, Z1&"!$F$2")
Explanation
INDIRECT requires a string that represents a cell or range references, like "Z1" but it will increase unnecessarily the complexity of your formula.
If Z1 has the name of the sheet, then just concatenate it by using CONCATENATE, CONCAT or &
UNTESTED. Please try something like:
=IMPORTRANGE(M4,Z$2)
with in Z2 something like:
=Z1&"!$F$2"
In other words, I think your IMPORTRANGE does not like INDIRECT.

Lock multiple cells in Google Spreadsheets with absolute reference ($)

Is there anyway to add a $ in front of all the cell references for formulas in my Google Spreadsheets without hand typing them in?
Ex: =Sheet1!H164 -> =Sheet1!$H$164
I have hundreds of formulas I need to do this for. I understand that F4 is a hotkey, but it would take years to lock the cell references that way.
For a column of formulae such as you show, select the column, Edit, Find and Replace..., Find !H. Replace with !$H$, check Also search within formulae and Done. Need to watch the likes of Wow!How was that possible but an entire sheet this way rarely takes a lot of Find/Replace, if reasonably well-structured.
I also recommend to use Find and replace (e.g. Find !A. Replace with !$A$)
But attention: If your sheet has entries in more than 26 columns, you would affect columns after Z, e.g. AA1 would become $A$A1 which will fail. You have to go through them afterwards manually and correct.
My solution is to use the INDIRECT formula.
Let's take an easy example. We want to apply =$A$1 to the entire a row.
Replace =$A$1 with =indirect("$A$"&row(A1)).
The INDIRECT formula can be dragged down as far as you want or combined with ARRAYFORMULA to do it automatically e.g.
=arrayformula(indirect("$A$"&row(A1:A100)))
(if you want to apply absolute referencing up to the row 100).

Resources