check for partially filled rows and delete the rows that don't have data in them - google-sheets

I have been working on a google sheet(sheet A) where the data comes from another sheet(sheet B) through importrange. In sheet A, column A contains all the urls, col C is the keywords and col F SEO keywords. I want to implement a function or an app script where for every url in column A, if the data is present in either column C or col F, that row should stay and if for url in column A, the data is col C and F is not present then the row should be deleted and the row below should move up. I am not sure how this should work. Can anyone please help me with the function or app script to be used for the same?

I am not sure I am understanding your question.
So there is an empty B column between A and C column? If so put this in B2 =if(sum(len(C4)+len(F4))>0,A4,"") It'll see if both C&F are empty and if so return a value of blank instead of the URL. You can then just copy-paste values only that over into Column A and you're set right?
From my understanding you want to keep combinations A,C - A,F - A,F,C & omit rows where it is just A as the only value?
If so this should get it done pretty easily. Are you doing this on like 10k+ row sheets?

You will not be able to move around rows with data that was imported with IMPORTRANGE in SheetA.
What you could do is write an Apps Script code to move around the source data in the source sheet since IMPORTRANGE gives you a live overview of the data in the source sheet. This might be the "cleanest" solution. In the source sheet you could have an onEdit trigger sorting your rows so that rows with empty columns are at the bottom. Then you can use IMPORTRANGE to import only the rows where all three columns have the data you want. (Extra careful with using IMPORTRANGE in apps script please, especially when counting rows afterwards due to lag)
Another option would be to just copy the values with a trigger instead of using IMPORTRANGE. This wouldn't be "as live as IMPORTRANGE" though but it would be easier to use the data.

If I understand you correctly, you are importing some data via IMPORTRANGE and you want to remove the imported rows in which columns C and F are empty.
If that's the case, you could use QUERY to filter out the undesired rows in the formula itself, so that they are not imported:
=QUERY(IMPORTRANGE("spreadsheet_url", "sheet_name!range"),"SELECT * WHERE (Col3<>'' or Col6<>'')")
Note:
If you wanted to use a script, the source data should not come from a formula (in that case, you should copy the imported data somewhere else and work with the copied data, which would not depend on the formula).

Related

IMPORTRANGE in Google Sheets preserving the structure of the destination sheet

Suppose that we have the following Google Sheet (called File_1):
And we import all the columns (A to C) via IMPORTRANGE("https://docs.google.com/spreadsheets/...", "Sheet1!A:C") into another sheet (called File_2), which also contains an additional column New_col with some data in it:
Now, suppose that the source sheet changes like this, i.e., a new row is added in-between the existing rows:
The destination sheet will become like this, in essence keeping Column D in its previous state and 'breaking' the relation of the 'test' value in cell D2 with the A1-B1-C1 row.
What I would like to have instead is the following destination sheet:
Is there a way to do that from within Google Sheets?
You are describing how formula results get misaligned with manually entered data. There is no turn-key solution to work around the issue. Lance has given a thorough treatment of the row misalignment issue and how it can be dealt with in some cases.

Trying to index match data from a different workbook

My colleague collects data in Google Sheet A. I want to reference and index-match some of that into my sheet B where I track the progress of projects. I've tried two different ways of doing it, and neither of them work for me.
Here are the two ways I tried:
I created a new tab in sheet B. Then I used importrange to sync with the data from sheet A. Then I used index match to reference the data from the importrange in the same sheet. Indexmatch did not work with the importrange data. Only once I copied and pasted it as values, did the data come over, but that of course broke the live synced importrange.
I tried to do the indexmatch and importrange at the same time using this formula from this forum:
=INDEX(IMPORTRANGE("SheetA",Tab"!A4:H26"),MATCH($Cell,IMPORTRANGE("SheetA",Tab"!A4:A26"),0))
But that just gave me an error.
Any other ideas on how to approach this?
use vlookup:
=VLOOKUP(A1; 'Sheet A'!A:H; 2; 0)
Maybe because it's just schematic, but have you used the quotation marks this way? --> Tab"!A4:H26"
You should use them like this --> "Tab!A4:H26"
And when you write "SheetA" you're writing the Spreadsheet Id, right??
And you should add another comma before the last parenthesis and tell which column you want to grab the final data from (1 for Column A, 2 for column B, etc.)

Connecting dynamic data with input in google sheets

I have gotten lost on a question in Google sheets re aligning dynamic data with static input data. At a high-level my problem is that I have dynamic data being pulled in a sheet where I also add in manual input data. Once the dynamic is changed it also means that the input data no longer corresponds to the right row.
Issue:
Sheet 1: I have an external data pull (Importdata) that dynamically pulls in new data.
Sheet 2: I use Query & Importrange to pull in parts of the data from sheet 1 (i only pull data where certain criteria are met)
Sheet 2: In sheet 2 I manually add data in columns next to the pulled data (J,M,N & O are input). The problem is, that when new data is pulled in from Sheet 1 it is then pulled through to sheet 2 and changes the order of the rows. This means that the manual data I have inputted no longer corresponds to the right rows.
Solution:
I need a way to ensure that the inputted data corresponds with the right row. So if a new row is pulled in the manually inputted data will follow the row where it was initially entered and move up/down with the row.
Sheets:
Link to Sheet 1 & Sheet 2
Really appreciate the help
Best
Palle
I'll attempt what I think is an answer here.
Basically, you need a unique key or identifier for each row of your dynamic data in Sheet1. Possibly, this could be the derivative_id. If not, you need to build a unique key, maybe derivative_id and the date, or some other combination.
Then you need an Update tab, where you would have the key, plus any other info you want to help guide in making your update. And then you have your four manual update columns - currently J, M, N, O in Sheet2.
Finally, Sheet2 becomes all automated - filled by formula only. Columns A:H continue to update dynamically, and all of the others are updated by formula, typically a VLOOKUP, as in column I, or a calculation, as in K and L. And columns J, M, N, and O will now do VLOOKUPS against the Update tab.
So even when Sheet 2 rows are updated or reordered, the "manual" data in J, M,N, and O will still stay with the correct row, since it is tied to a unique key for the data in that row.
If this all makes sense to you, I can put together an example for you.

ARRAYFORMULA with IMPORTRANGE

In column B are listed IDs of Google Sheets. In column C are listed cells, from which I want to import data.
Screenshot of the table
In column D is shown the result of using IMPORTRANGE() by simply dragging it. e.g. for D1 it looks like:
=IMPORTRANGE(B1;C1)
for D2:
=IMPORTRANGE(B2;C2)
and so on.
In column E I want to display the same result but using ARRAYFORMULA that looks like:
=ARRAYFORMULA(IMPORTRANGE(B2:B4,C2:C4))
but the function displays only the data from the first spreadsheet.
People complain about this permissions issue a lot, but it's not hard to solve. What I do is have a sheet which I name "Splash sheet" into which I paste the URLs of the documents I wish to link. To its right is a column headed "permit to connect" which contains IMPORTRANGE formulas importing a single cell from each sheet -- usually a cell containing a confirmation code, number or document name -- on a sheet also named "Splash Sheet." For example,
=IF(B3="enter URL",,CONCATENATE(IMPORTRANGE(B3,"Splash sheet!A1")," ",IMPORTRANGE(B3,"Splash sheet!B1")))
So, when you first connect a spreadsheet via its URL, you get those messages telling you you need to connect, you click the Permit Access, the confirmation code/number/document name appears in the second column, and voilá, your sheets are connected forevermore! Now all your other IMPORTRANGEs referencing that URL will work, and you can use IMPORTRANGE formulas that reference the URL-containing cells on the "splash sheet."
As for the OP's original question, I came here seeking an answer to the same problem, and after more research have realized that we are attempting the impossible here. No way to do this an ARRAYFORMULA. No way around writing formulas that reference every single cell a document's URL may go into.
Problem is you can't make arrays of arrays in spreadsheets; that would involve multiple dimensions, and the medium is inherently two-dimensional. This is what people use databases for.
ARRAYFORMULA doesn't work when importing data (I think it relates to permissions). You could use something like this, =IFERROR(IMPORTRANGE(B5:B7;C5:C7)) and pre-fill the column first, but still there would be the permissions issue. Each new imported sheet needs it's permissions granted by a user.
TLDR: If I understand your intention correctly when you say you would like to see
=ARRAYFORMULA(IMPORTRANGE(B2:B4,C2:C4)), I believe you can make that
happen using the following.
=ARRAYFORMULA(IMPORTRANGE(
INDIRECT(ADDRESS(ROW(B2:B4), COLUMN(B2:B4)),
INDIRECT(ADDRESS(ROW(C2:C4), COLUMN(C2:C4))
)
Breakdown
Use IMPORTRANGE with INDIRECT to create ranges inside ARRAYFORMULA
Call INDIRECT with the ADDRESS function
Call ADDRESS with the ROW and COLUMN functions since they take ranges via ARRAYFORMULA
using IMPORTRANGE with INDIRECT
IMPORTRANGE's two parameters are the spreadsheet url stored in B2:B4 for this example and the range (e.g. sheet!A1:B2) stored in C2:C4.
Since IMPORTRANGE doesn't take a range reference directly as you mentioned, you'll need to build it for each row with ARRAYFORMULA using the INDIRECT function.
INDIRECT can be used to compose a cell reference using A1 notation, for instance
=IMPORTRANGE(INDIRECT("B" & 2), INDIRECT("C" & 2))
will produce the same result as
=IMPORTRANGE(B2, C2)
Since this produces the same result, we now just have to find a way to make INDIRECT work with ARRAYFORMULA
Use ADDRESS to build the parameters for INDIRECT
Next you want to use ADDRESS to build the A1 reference for INDIRECT. For the current purposes, ADDRESS takes a numerical value for row and column as parameters
=INDIRECT(ADDRESS(2,2))
will produce the same result as
=INDIRECT("B" & 2)
Since these two are interchangeable, now we just need to find a way to get the numerical row and column values out of ARRAYFORMULA.
Call ADDRESS using the ROW and COLUMN functions
From there, you can get the row and column indexes from standard A1 notation using the ROW and COLUMN functions. While this may seem like we're pointlessly going in circles, the difference now is that ROW and COLUMN perform as expected with the ranges provided by ARRAYFORMULA. So given that ADDRESS will return $B$2 using using either method below
=ADDRESS(2,2)
or
=ADDRESS(ROW(B2),COLUMN(B2))
we now know that
=ARRAYFORMULA(ADDRESS(ROW(B2:B4),COLUMN(B2:B4)))
will produce the following array of addresses
{ $B$2; $B$3; $B$4 }
Final Assembly
So when we put this all together, we get
=ARRAYFORMULA(IMPORTRANGE(
INDIRECT(ADDRESS(ROW(B2:B4), COLUMN(B2:B4)),
INDIRECT(ADDRESS(ROW(C2:C4), COLUMN(C2:C4))
)
where INDIRECT(ADDRESS(ROW(B2:B4), COLUMN(B2:B4)) is more or less interchangeable with what you might expect from B2:B4 inside ARRAYFORMULA and represents the url parameter
and INDIRECT(ADDRESS(ROW(C2:C4), COLUMN(C2:C4)) is roughly interchangeable with what you might expect from C2:C4 inside ARRAYFORMULA and represents the range parameter.
Suggestions on organization
I recommend using the indentation (Alt +Enter to create a new line ) above along with your indentation of choice to keep it easier to read. In the end it's just a bit more syntactic sugar and if spaces are used well it shouldn't be much harder to understand and make changes to 6 months later.
RE: Permissions - as mentioned by Atiq Zabinski, just placing a simple
IMPORTRANGE("http:/xxxx", "A1") somewhere on the sheet will provide a
means to know if the sheet is connected or not and the error message
should give you a context menu for connecting the sheet. You'll might
want to stay away from error handling in these scenarios as it will
slow down the process of connecting the sheets.

How to use ARRAYFORMULA + FILTER within Google Spreadsheet?

I have a Google spreadsheet with basically a dictionary of key/value pairs. Keys are unique. In a second sheet I need to add one or more rows for every key in the dictionary with some data. In this very sheet I'd need to also report the proper value for each key.
To do so I have tried to combine the ARRAYFORMULA function with a number of other functions on the very first row of the second sheet to avoid (if possible) the need to copy the same formula on all rows of the value column.
So far, neither QUERY nor FILTER worked.
QUERY requires all data, there included the arguments to the WHERE predicate, to reside on a single sheet. In my case, the filtering key would be on the second sheet while the dictionary is on the first one. So this cannot be used at all.
FILTER seems to have a weird (to me) behavior when both used in conjunction with ARRAYFORMULA and without it.
You can have a look to my test Google Sheet
here or to snapshots here with ARRAYFORMULA (column B), without it (column C) and what I'd like to get (column D):
A little step further from pnuts' solution provides the "perfect" result without the "N/A" cells:
=ARRAYFORMULA(IF(A3:A="";"";VLOOKUP(A3:A;KEYS!A1:B;2;FALSE)))
Of course there is a major impact on the performances as the VLOOKUP is run once for every single line in in the second sheet (and this was also why I was trying to use FILTER).
Those performances are quite low even with the currently linked example sheet, which is really skinny.
In Row3 please try:
=ArrayFormula(vlookup(A3:A;KEYS!A$1:B$5;2;0))
you can use a From spreadsheet - On change event trigger to call code like below:
function CopyPasteWastageRows() {
var spreadsheet = SpreadsheetApp.getActive().getSheetByName("<<Sheet-Name>>");
spreadsheet.getRange('Q2').activate();
var currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
spreadsheet.getRange('Q2').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
spreadsheet.getRange('Q2').activate();
};
Try:
=ARRAYFORMULA(IF(LEN(A3:A); VLOOKUP(A3:A;KEYS!A1:B;2;FALSE);))
That should get the keys, as far as values are entered in col A.

Resources