skip to Main Content

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?

3

Answers


  1. 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?

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. 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).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search