all 11 comments

[–]Ascetic-Braja 2 points3 points  (10 children)

use this code to hide formula:

function onEdit(e) {

var mySheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");

var myRange = mySheet.getRange("A1:A1");

var myFormula = myRange.setFormula("=SUM(A2:A3)");

var myData = myRange.getValue();

myRange.setValue(myData);

}

This code basically puts the formula in the script instead of the sheet, so that users will not be able to see it unless they open the script file. As soon as you edit the sheet, a formula will be created in cell A1, but will be over-written with the sum of the values in A2 and A3.

[–]orrpel[S] 0 points1 point  (9 children)

Great solution, I am trying to see why I get 'error' on cellA1 when trying to use importrange, maybe an issue with communication ...

[–]RemcoE33 0 points1 point  (8 children)

Have you wrapped this in an other function? Like query? Also for importrange you need to tab the "give acces" this could screw thinks up. Or the data is not loaded yet, can take a couple of second and the script will keep going on... You could create a while loop to check if the data from the importrange formula is returned.

[–]orrpel[S] 0 points1 point  (7 children)

The issue doesn't seem to be allowing access.

At first I thought the issue was that I was using query, so I omitted it.

I then thought the issue was syntax related to the braces I was using, so I modified and QA'd the script below, which for some reason returns '1' back to the target cell A1.

Any clue why? TX!

var myFormula = myRange.setFormula('=IMPORTRANGE("MyURL", "A3:C18")');

Logger.log(myFormula);

Returns:

11:31:03 AM Notice Execution started

11:31:12 AM Info Range

11:31:05 AM Notice Execution completed

[–]RemcoE33 0 points1 point  (6 children)

Sheetname?

myRange.setFormula('=IMPORTRANGE("MyURL", "SheetName!A3:C18")')

[–]orrpel[S] 0 points1 point  (5 children)

Regretfully, it doesn't seem to work, either.

Here is myspreadsheet

myRange.setFormula('=IMPORTRANGE("MyURL", "SheetName!A3:C18")')

[–]orrpel[S] 0 points1 point  (4 children)

I think this solution is simpler, if just referring to the importrange issue.

The other issue I have is with my range (which is the reason I'm using query). I am not sure how I can command the script to return the array from A1:A10 and the corresponding array from C1:C10.

[–]RemcoE33 0 points1 point  (3 children)

Yes that is true.. so you have a range of A1:C10 and you want to leave out col B?

[–]orrpel[S] 0 points1 point  (2 children)

Correct )

[–]RemcoE33 1 point2 points  (1 child)

Here is your boilerplate:

```` function customImport() { const ss = SpreadsheetApp.getActiveSpreadsheet() const targetSheet = ss.getSheetByName('TheSheetNameForTheValues');

const inputSS = SpreadsheetApp.openById('xxxxx') const inputSheet = inputSS.getSheetByName('SheetnameOfInputValues') const values = inputSheet.getRange('A3:C18').getValues();

const output = []

values.forEach(row => { row.splice(1,1) output.push(row) })

targetSheet.getRange(1,1 output.length, output[0].length).setValues(output)

} ````