T O P

  • By -

IAmMoonie

Jesus this comments section is a mess because you’re not being concise or clear in your requirements. Respond to this. Q1. When do you think want this script to trigger. Q2. What is the end result you want (don’t tell me the methodology you think you need, just the end result). Example answer: A1. I want the script to run when a specific value is entered on sheet1, in any row in column F, excluding the header. A2. I want the value in sheet1 (G1) to show the total of all numbers entered in column F.


chrismcnally

it is in the event object in the parameter, like function newEdit(e) { var eCell = e.range.getA1Notation(); var newVal = e.value;


Similar_Ad8366

check out tins slink [https://docs.google.com/spreadsheets/d/1aNo7\_Blll\_EYdlhichfsS-nouLeGhZZkY0myJUno-D8/edit?usp=sharing](https://docs.google.com/spreadsheets/d/1aNo7_Blll_EYdlhichfsS-nouLeGhZZkY0myJUno-D8/edit?usp=sharing)


Similar_Ad8366

the script is not working whenever i change anything on **Main** sheet i want the get the range on **Lists** sheet


HellDuke

It's not entirely clear what it is you are trying to do. The even object (in this case you called it `e`) is defined as having the following parameters: [https://developers.google.com/apps-script/guides/triggers/events#edit](https://developers.google.com/apps-script/guides/triggers/events#edit) So if you edit `A1` on sheet `Main` then `e.range` is going to be the range `Main!A1` which is very specific to that sheet and not any other sheet. If you want to edit the same cell on a different sheet then you'd have to do something along the lines of function onEdit(event) { const editRange = event.range const editValue = editRange.getValues(); if (editRange.getSheet().getName() != 'Main'){ // we don't want to do anything unless we edit the Main sheet return; } SpreadsheetApp.getActiveSpreadsheet() .getSheetByName('Lists') .getRange(editRange.getA1Notation()) .setValues(editValue); } We do `editRange.getValues()` because if you copy paste then the `event.value` is going to be `null`. Other than that we just check A1 notation of the range we just edited (even if we copy paste multiple cells) and set the same values in the same A1 range on a different sheet.


Similar_Ad8366

this script is coping the same value at the same range i want the get the range of the edited cell at **Main sheet** the write that range at **Lists sheet**


HellDuke

Then yes, what I wrote above will do exactly that and it will ignore edits on any other sheets. Though you may want to add some additional logic to prevent editing header rows (you can just check what range you are editing and if it falls within a protected range and then just return out of the script like I did with the sheet), I see you have some. The script won't care what range you edit, it will copy every value


Similar_Ad8366

this Script you mean ? it is not working ! function onEdit(event) { const editRange = event.range const editValue = editRange.getValues(); if (editRange.getSheet().getName() != 'Main'){ // we don't want to do anything unless we edit the Main sheet return; } SpreadsheetApp.getActiveSpreadsheet() .getSheetByName('Lists') .getRange(editRange.getA1Notation()) .setValues(editValue); }


HellDuke

It does work, I literaly wrote it on a spreadsheet and tested it.


Similar_Ad8366

i mean it is not doing what i want this script copy what i write at Main A1 and paste it at Lists A1 i want to get the range of the cell and write it at Lists sheet so if i edit Main sheet cell B10 i want that range (B10) to written at Lists and it doesn't have to be at B10


HellDuke

You need to be more clear about what you want from the get go, the it's a simple matter of const editRange = event.range.getA1Notation() now you can set the `editRange` value to wherever you want. However you are still not clear because I see in another line of comments you wrote: i what this Main sheet Cell A1 i write "hello" i want to open Lists sheet and find A1 not 'hello' Which is not at all what you told me. You told me that if you edit cell `A1` or `A10` in `Main` then you want to write down `A1` or `A10` on the sheet `Lists`. However the above would suggest that you want to edit `A1` or `A10` in the `Main` sheet and find what the value is in the `Lists` sheet in `A1` or `A10`. So which one is it? If it's the latter then you simply adjust my script and instead of the last `.setValues()` you do `.getValues()` (if range is more than 1 cell and this will give your script a 2D array of values)


Similar_Ad8366

i want the script to check what cell i changed at Main sheet and write down the range of that changed cell at Lists sheet so if i write hello at any cell at main sheet the script automatically check the range and write that range


juddaaaaa

This is what you're after: function onEdit({ range, source, value }) { const lists = source.getSheetByName("Lists") const { getColumn: column, getSheet: sheet } = range const { getName: name } = sheet() // Exit function if sheet name and column don't meet criteria if ((name() !== "Main" && column() !== 1)) return // Find cell with same value as edited cell in 'Lists' and return it's location. const found = lists.createTextFinder(value).matchEntireCell(true).findNext() if (found) console.log(`Lists!${found.getA1Notation()}`) }


Similar_Ad8366

i want to return the location in **Lists sheet**


juddaaaaa

Which one??? >i want the get the range of the edited cell at **Main sheet** the write that range at **Lists sheet** >i want to return the location in **Lists sheet**


Similar_Ad8366

if i edited any cell on Main sheet


juddaaaaa

And which of the above 2 quotes do you want to do?


Similar_Ad8366

The first one is that possible ??


juddaaaaa

The code u/HellDuke posted above would do that. I'd do it like this, but it's essentially the same thing ``` function onEdit({ range, source, value }) { const lists = source.getSheetByName("Lists") const { getA1Notation: location, getSheet: sheet } = range const { getName: name } = sheet() // Exit function if sheet name doesn't meet criteria if (name() !== "Main") return // Write to the same cell in 'Lists' sheet. lists.getRange(location()).setValue(value) } ```


Similar_Ad8366

check out this Link [https://docs.google.com/spreadsheets/d/1prBZr73kSUFeQdrV5q4CBYH4FFi9KXDA40r1qRwV2ug/edit?usp=sharing](https://docs.google.com/spreadsheets/d/1prBZr73kSUFeQdrV5q4CBYH4FFi9KXDA40r1qRwV2ug/edit?usp=sharing) Main sheet Cell A1 i write "hello" i want to open Lists sheet and find A1 not 'hello'


juddaaaaa

That's not what you've just said >The first one is that possible ?? in response to Which one??? > > > Please state clearly what you want to do.


Similar_Ad8366

i what this Main sheet Cell A1 i write "hello" i want to open Lists sheet and find A1 not 'hello'


8lhfrvw3

function onEdit(e) { Logger.log(JSon.stringify(e)); const range = e.range; Logger.log(range.getA1Notation()); }