A
A
Andrew2018-03-29 17:20:00
Google
Andrew, 2018-03-29 17:20:00

Google Sheets - How to make interdependent cells from different sheets of the same workbook?

Good time of the day! I already got acquainted
with a similar question on the Toaster . A day of Google and ignorance of js did not help to adapt this or that script to my conditions.

Script No. 1 (not readable by GS at all)
Private Sub Worksheet_Change (ByVal Target As Range)
If Not Intersect(Target, Union([A1],[B1])) Is Nothing Then
Application.EnableEvents = False
[B1]= Target
[A1]= Target
Application.EnableEvents= True
End If
End Sub
Script #2 (works within 1sheet and only cells2->cells1 | need cells1<->cells2 )
function onEdit(e) {
var cells1 = ["A1", "C3", "A6"];
var cells2 = ["B2", "D1", "E4"];
var value = (typeof e.value == 'object' ? "" : e.value);
var sheet = e.range.getSheet();
var cell = e.range.getA1Notation();
var k = cells1.indexOf(cell);
if (k != -1) {
sheet.getRange(cells2[k]).setValue(value);
}
k = cells2.indexOf(cell);
if (k != -1) {
sheet.getRange(cells1[k]).setValue(value);
}}
Given:
Google Sheets - 1 book: 2 sheets. New lines are constantly added
Task:
When entering a value in one cell, copy/duplicate this value to a cell in another sheet and vice versa automatically
I.e. - 'sheet1'!A:A='sheet2'!A:A (Column A of sheet1 = Column A of sheet2) with the ability to edit the values ​​of these cells

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lrv, 2018-03-31
@lrv

You can write a macro that will be triggered when the values ​​in the cells change. Private Sub Worksheet_Change(ByVal Target As Range). Specify the range in which you want to track changes and then write a condition if the cell falls into the specified range. If it hits, drive values ​​from the first sheet into an array, delete everything on the second and insert data from the array into the same range. Only not a cycle, but it will work for a long time. Copy and paste via Range.
Ps The macro for changing values ​​in cells is inserted into the sheet module.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question