Google Sheets - linked via importrange and inserting a new row - google-sheets

I have two spreadsheets:
A budget sheet, with estimated costs and actual costs
A cost tracking sheet, with the actual costs and reference to receipts
Currently I am importing the 'actual costs' in the budget sheet, by referencing rows from the 'actual costs' in the tracking sheet
So my budget sheet references the cost tracking sheet this way:
=(importrange("spreadsheet_key","sheet_name!I76"))
This works fine, however, if I insert a new row into my cost tracking sheet above some of the values I am already referencing, it will not dynamically update.
So if I insert a new row above:
=(importrange("spreadsheet_key","sheet_name!I76"))
I then have to manually change it in the other sheet to:
=(importrange("spreadsheet_key","sheet_name!I77"))
Is anyone aware of a way I can link two sheets and still be able to insert rows without this breaking?
Thanks

Construct the range reference with the Address function. This produces a string representing the target range.
=importrange("spreadsheet_key", address(row('sheet_name'!76:76), column(I:I), 4, true, "sheet_name"))
Adding or deleting a row above row 76 on the sheet_name worksheet will adjust the range address accordingly.

Related

How to use CountIf in Google Sheets that only counts cells if there is content in another cell?

I need some help with a CountIf type formula in Google Sheets.
I have a large spreadsheet of a consolidated NHL schedule where I am going to enter stats that I care about. In a separate spreadsheet I am going to have averages for the stats I care about.
I want to have a formula that uses the Column A of Sheet2 to count the games in Sheet1 that have content in the other cells of Sheet1 (so, games that have been played).
If this works then Column B of Sheet2 will have the correct # of games played which is all the cells that have content/stats next to the teams name in Sheet1 so that I dont have to manually update that part and then the count of games played can go straight to the average formula.
The pictures are manually entered but just showing that since the Blackhawks have content next to their name in Sheet1, I would want Sheet2 Column B to read 1 based on a formula.
Thanks!!!
Sheet1
Sheet2
I would just do a COUNTA on a column (so that counts the rows in a specific column that are not blank), on a filtered table that match the team names:
So:
=COUNTA(FILTER(Sheet1!D:D,Sheet1!B:B=A3))

Google Sheets - linking two separate sheets and importing values

I have two spreadsheets:
A budget sheet, with estimated costs and actual costs. Replicated here: https://docs.google.com/spreadsheets/d/1J8wPicVyfs98QXRXRCHZoq-Y6Uoi75Iv8WitGja4Pic/edit#gid=0
A cost tracking sheet, with the actual costs and reference to receipts. Replicated here: https://docs.google.com/spreadsheets/d/1YclB3V3817Q-RGwuzrOXoZkarwFszaTqwUFurtYtLVo/edit#gid=0
Currently I am importing the 'actual costs' in the budget sheet, by referencing rows from the 'actual costs' in the tracking sheet
So my budget sheet references the cost tracking sheet this way:
=(importrange("spreadsheet_key","sheet_name!I76"))
This works fine, however, if I insert a new row into my cost tracking sheet above some of the values I am already referencing, it will not dynamically update.
So if I insert a new row above:
=(importrange("spreadsheet_key","sheet_name!I76"))
I then have to manually change it in the other sheet too for each item:
=(importrange("spreadsheet_key","sheet_name!I77"))
Is anyone aware of a way I can link two sheets and still be able to insert rows without this breaking?
Thanks
Sounds like you want a sheet that updates when new values are entered into a separate sheet? I think a short script similar to the one proposed in this question should work for you.
Detect user inserting row or column in a google spreadsheet and reacting in a script

Last row in google sheets

I'm sure this will be answered VERY quickly but its beginning to do my head in!
I have a stockcheck spreadsheet in Google Sheets. The stock check is done on a tablet and the data is sync'd with google sheets whereby the data from that stock check is appended in rows consecutively.
So week 1 would transfer to row 1, week 2 to row 2 etc etc etc.
The number of items on the stock check may decrease or increase to the length so consequently so the row length will do as well.
I want to transfer that raw data to a second sheet but only the last row, so I can in effect get the data from the most recent stock check.
I've tried numerous functions and can return both the number of the last row and the value of the first column in the last row.
I'm just at a complete loss in returning the values of the entire last row. Please help!
Without an example of your inventory sheet, I had to make one that is extremely simple (only has 3 columns). Next time, it would be helpful if you shared a link to your sheet (or at least made a copy of your sheet with insensitive data that you could share with us). Baring that data, I had to assume that you want the LATEST inventory row, and that you have a column with the date of the inventory in it...
Here's the sheet I created:
https://docs.google.com/spreadsheets/d/1_H73BKJJDYdJYmKz6C_qDCzQ5TaByo6PcED2nRFCDBQ/edit?usp=sharing
Basically, I created a filter in Cell A1 that gets all the columns in your range, and then returns that data filtered by all dates that are in the past, orders the array by date, and then limits the rows returned by 1 (and the columns by the number of columns in your range):
=array_constrain(sort(filter($A$4:$C,$A$4:$A<=today()),1,false),1,columns(A:C))

Using VLOOKUP with an additional VLOOKUP on FALSE

I am trying to use vlookup in Google Sheets to populate my price data in my inventory database called "Food Inventory". The data I am looking to match is the "description" which is the A column in all three sheets.
I have a price data sheet with a named range pricedata and an Old Price Data sheet with a named range oldprice.
I would like to find the most current price data and if there is no match look in the Old price data sheet.
Here is the formula I am using which is not working:
=VLOOKUP(A3,PriceData,4,0),VLOOKUP(A3,oldprice,4,0)
I would prefer not to use array formulas, if possible.
Almost there but one can't link two VLOOKUPs with just a , in the way you attempted. If the first attempt (in PriceData) fails an error will be returned. This can be used to trigger the second attempt with IFERROR:
=iferror(VLOOKUP(A3,PriceData,4,0),VLOOKUP(A3,oldprice,4,0))

Setting formula range from first to last populated cell in a column?

For a league I run we keep track of games played and w/l/t and calculate that into a ranking score. The player name is listed in column U and the ranking score in column AD of a fixed table. I then use an array formula to list the players in ranking order in column E (then vlookup to pull in other stats based on the value in E for that row). Specifically I use this formula in column E:
=ARRAY_CONSTRAIN(ARRAYFORMULA(INDEX($U$4:$U$153,MATCH(LARGE($AD$4:$AD$153-ROW($AD$4:$AD$153)/COUNT($AD$4:$AD$153),ROW(E72)-ROW(E$4)+1),$AD$4:$AD$153-ROW($AD$4:$AD$153)/COUNT($AD$4:$AD$153),0))), 1, 1)
I need to be able to add players to the table in U:AD without having to edit the formula every time, i.e. from $U4:$U153 and $AD$4:$AD$153 to $U4:$U154 and $AD$4:$AD$154 in all the various places in the formula then copy the new formula all the way down.
Is there a way that I could define the range as $U$4:$U(last populated row) and the same for column AD in the above formula?
I eventually be using this in both Excel and Google Sheets so I would really like to avoid scripting. First I'm looking to solve this for Google Sheets.
Here is a copy of the sheet I am working on.
You could use INDEX and COUNTA
Instead of $U4$U153,
$U4:INDEX(U4:U,COUNTA(A4:A))
The COUNTA portion will give the number of populated rows and feed it into INDEX to give $U4:$U153
The answer for the Google sheet that you shared.
skip to the end for the simple solution
I used the indirect method by entering a formula in E1 that counts the AD column for player stats and adds 3 to get the last row. (I was going create the full range AD4:AD?? but you also have U4:U73 in the formula)
=counta(AD4:AD)+3
I then changed your formula use indirect, indirect("$AD$4:AD"&E$1), to reference the last row number in cell E1 to create the required range.
=iferror(ARRAY_CONSTRAIN(ARRAYFORMULA(INDEX(indirect("$U$4:U"&E$1),MATCH(LARGE(indirect("$AD$4:AD"&E$1)-ROW(indirect("$AD$4:AD"&E$1))/COUNT(indirect("$AD$4:$AD"&E$1)),ROW(E4)-ROW(E$4)+1),indirect("$AD$4:$AD"&E$1)-ROW(indirect("$AD$4:$AD"&E$1))/COUNT(indirect("$AD$4:AD"&E$1)),0))), 1, 1),"")
I discovered by accident that if you remove the ARRAY_CONSTRAIN from your formula and change U4:U73 to U4:AC73 then the formula will populate the scores to the right of your formula where you currently have vlookups. I put an example of this in E4 but note that you will have to delete the vlookup formulas if you want to fill the formula down otherwise it will show REF
I also added iferror so that the formula can be copied to the same row as the end of the "open slots" in column A without showing errors.
Also, I got to this point and was thinking that since you're using Google Sheets, a better way to do this could be to use the QUERY function to pull the data and also sort it using ORDER BY with a single formula in cell E4.
I've not really used the QUERY function but maybe it's time to learn.
EDIT
Turns out it doesn't take much learning
=QUERY(U4:AD,"SELECT U,V,W,X,Y,Z,AA,AB,AC ORDER BY AD DESC")
Put the formula above in cell E4 and delete everything beneath and scores to the right and you're done. you'll notice that there is no indirect because Google understands that you don't want the blank rows.
https://docs.google.com/spreadsheets/d/16IclEmKwDFdInIAZhH2vt-tLJ5pbwX06jv9xrUXwhnY/edit?usp=sharing
Why are you using $ signs around U4:U153,remove $ signs for rows that will give you flexibility while keeping columns fixed.As your drag the formula,the data array will append the newly filled cells or you can create table using Ctrl+T that will automatically expand as you keeping adding data.

Resources