Entangle 2 cells / have 2 cells act as one

Hello,
what i’m trying to achieve: have cells A1 and Z1 act as if they were the same cell.

entering a value “x” in A1 should cause “x” to show in Z1
deleting the same value “x” in Z1 or overwriting it with a value “y” should cause A1 to change accordingly

the workaround i’m currently using: cell A1=Z1 and cell Z1=A1 unfortunately i’m editing the entered values a lot -it’s a planning document- and copying a formula every time i’m changing a value from “x” to nothing is not the solution i’m hoping for.

Hopefully this is the right kind of question for this forum, i guess i simply couldn’t find the right terminology to figure it out via google.

LibreOffice 7.2 on win64

Thank you for your time, kind regards

Martin

Can you please still share what is the background of an editable copy. I would like to understand it. Thank you.

Tell me, Martin, will you never use formulas in these cells? That is, you are interested only in the values? The fact is that it is not very difficult to implement this behavior of the table - to change the value in several places of the same sheet at once. How many of these pairs of linked cells would you like to have on your sheet?

@Hrbrgr

Sure. I’m trying to improve the shift and overtime planning of the small restaurant that i work in.

my sheet would contain the dates of a month in A2:A32
the employee name ‘Adam’ in B1
the different shifts Adam will do in B2:B32 denoted by abbreviations such as ‘SE’ for service early shift
the hours associated with those shifts in C2:C32 (called via VLOOKUP in a different sheet)
some overtime calculations in C44:C50
columns D and E will have ‘Bertha’ in them, columns F and G will have ‘Charlie’ and so on
the restaurant employees take up columns A:AD, the kitchen employees take up columns AF:BN

Since some employees work in both kitchen and restaurant i would like to have the described ‘editable copy’ - thank you for that term, very much to the point.

Thanks for commenting.

There is a possibility to make entries in two or more tables at the same time.
If you select table A and table B at the same time and, for example, make an entry in cell A1 in table A, this entry will then also appear in table B, A1.
To use this possibility for your purposes, you would of course have to split your table into several tables and arrange the cells accordingly.
I hope I have been able to illustrate this in an understandable way.

@JohnSUN

Thank you for the suggested solution, i will be looking into that later today.
As for the questions in your first post:

  • formulas will not be used in the linked cells, just a range of abbreviations such as “SE” “KL” which in turn will be used by a VLOOKUP
  • a total of 124 individual cells

Thank you for now.

So, 62 pairs?

@JohnSUN

oh, no, sorry. 124 pairs.

So, we need to create 124 cell styles … It’s difficult to do it manually. I will try to make this part of the job easier.

By the way, the second solution (without a macro) for such a number of pairs would be even more time consuming, you don’t even need to think about this solution.

@Hrbrgr

Understood. Splitting the tables might be the better way to go about this to begin with and i never knew about the functionality you described.
Works fine in the quick example i put together.

Thank you very much!

1 Like

@JohnSUN

Thank you for your help - and what i can only describe as awesome commitment.

Since the solution @Hrbrgr suggested would work fine for my purposes there would be no need -on my part- for you to look further into this.

Thanks again.

This solution uses a macro that will fire when any cell in the sheet changes.

First of all, create a custom cell style. Click F11 to open the window Styles.

Styles

Right click on the Default style and select New. Give the style a name that begins with a keyword. I used the _related prefix as an example.

CreateCustomStyle

You can also assign a background color to this style to help you avoid mistakes when laying out linked cells. When the sheet is ready, you can reset this parameter to None.

Create as many styles as you are going to create links, just add the following number after the prefix.

Now add a macro with the following code to the Standard module of the current spreadsheet:

Option Explicit 

Sub onCellValueChanged(oEvent As Variant)
Const START_STYLE_NAME = "_related"
Dim oSpreadsheet As Variant
Dim oSearchDescriptor As Variant
Dim oFound As Variant
Dim oRange As Variant
Dim oCell As Variant
Dim i As Long, j As Long, k As Long
	If oEvent.supportsService("com.sun.star.sheet.SheetCell") Then
		If Left(oEvent.CellStyle, Len(START_STYLE_NAME)) = START_STYLE_NAME Then
			oSpreadsheet =oEvent.getSpreadsheet()
			oSearchDescriptor = oSpreadsheet.createSearchDescriptor()
			
			oSearchDescriptor.SearchStyles = True
			oSearchDescriptor.setSearchString(oEvent.CellStyle)
			oFound = oSpreadsheet.findAll(oSearchDescriptor)
			
			For i = 0 to oFound.getCount()-1
				oRange = oFound.getByIndex(i)
				If oRange.supportsService("com.sun.star.sheet.SheetCell") Then
					oRange.setString(oEvent.getString())
				Else
					For j = 0 To oRange.getRows().getCount()-1
						For k = 0 To oRange.getColumns().getCount()-1
						oCell = oRange.getCellByPosition(k,j)
						oCell.setString(oEvent.getString())
						Next k
					Next j
				EndIf 
			Next i			
		EndIf 
	EndIf 
End Sub

Now right click on the sheet tab and specify that this subroutine should run for the Content changed event.

Demo example - multycell_editing.ods (11.2 KB)

Another solution (without a macro) can be implemented using the CheckBox controls located in the linked cells. It is enough to specify the same Linked Cell in the properties of different controls (for example, A1 for your example).

ControlData

In this case, cell Z1 will indeed contain the formula that you indicated in the question. Clicking on these checkboxes will change the value in one cell, but this value will be displayed wherever there is such a formula.

@JohnSUN

…
			oFound = oSpreadsheet.findAll(oSearchDescriptor)
			
			for each ocell in ofound.Cells
				ocell.setString(oevent.getString())
			next
		EndIf 
	EndIf 
End Sub

1 Like

Yes, it’s much easier that way