ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   sheets that mirror each other (https://www.excelbanter.com/excel-programming/436772-sheets-mirror-each-other.html)

Robert Crandal

sheets that mirror each other
 
My workbook only has 2 sheets. If the user edits cell "A1"
on Sheet1, I want that data to be copied into "A1" on Sheet2.
My users also work on Sheet2, so if they edit cell "A1" on
Sheet2, I need to copy that same data to the "A1" on Sheet1.

How can I do this?



trip_to_tokyo[_3_]

sheets that mirror each other
 
Hi Robert.

I don't think that you can do that.

You can do the following:-

1. Enter the data in sheet 1 cell A1.

2. On sheet 2 at cell A1 enter the following:-

=Sheet1!A1

3. This way the data in both cells will be identical.

4. I do not think that you can do the, €śvice / versa€ť though.

If my comments have helped please hit Yes.

Thanks!



"Robert Crandal" wrote:

My workbook only has 2 sheets. If the user edits cell "A1"
on Sheet1, I want that data to be copied into "A1" on Sheet2.
My users also work on Sheet2, so if they edit cell "A1" on
Sheet2, I need to copy that same data to the "A1" on Sheet1.

How can I do this?


.


Mike Fogleman[_2_]

sheets that mirror each other
 
In sheet1 code module put this:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheet2.Range(Target.Address).Value = Target.Value
End Sub

in Sheet2 code module this:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheet1.Range(Target.Address).Value = Target.Value
End Sub

Mike F
"Robert Crandal" wrote in message
...
My workbook only has 2 sheets. If the user edits cell "A1"
on Sheet1, I want that data to be copied into "A1" on Sheet2.
My users also work on Sheet2, so if they edit cell "A1" on
Sheet2, I need to copy that same data to the "A1" on Sheet1.

How can I do this?





Robert Crandal

sheets that mirror each other
 
Wouldn't this cause an infinite loop or something???
Sheet2 will try to mirror the contents of Sheet 1, but
Sheet 1 will also notice the cell change and try to mirror Sheet2
and vice versa, on and on and on???

What do you think?

"Mike Fogleman" wrote in message
...

In sheet1 code module put this:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheet2.Range(Target.Address).Value = Target.Value
End Sub

in Sheet2 code module this:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheet1.Range(Target.Address).Value = Target.Value
End Sub



Mike Fogleman[_2_]

sheets that mirror each other
 
It worked OK on my test sheets. This assigns a value to a cell and does not
trigger the Change event in the other sheet. Editing the cell does, but only
for that sheet.

Mike F
"Robert Crandal" wrote in message
...
Wouldn't this cause an infinite loop or something???
Sheet2 will try to mirror the contents of Sheet 1, but
Sheet 1 will also notice the cell change and try to mirror Sheet2
and vice versa, on and on and on???

What do you think?

"Mike Fogleman" wrote in message
...

In sheet1 code module put this:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheet2.Range(Target.Address).Value = Target.Value
End Sub

in Sheet2 code module this:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheet1.Range(Target.Address).Value = Target.Value
End Sub





Robert Crandal

sheets that mirror each other
 
Try putting a MsgBox("Im in Sheet1") statement in the
Worksheet_Change() function for sheet1. It will
give you about 45 message boxes/dialog boxes that
say "I'm in Sheet1". It appears that Excel runs out of
stack space at that point.

so it appears that the Change event is triggered in the
other sheets as well.

"Mike Fogleman" wrote in message
...
It worked OK on my test sheets. This assigns a value to a cell and does
not trigger the Change event in the other sheet. Editing the cell does,
but only for that sheet.

Mike F
"Robert Crandal" wrote in message
...
Wouldn't this cause an infinite loop or something???
Sheet2 will try to mirror the contents of Sheet 1, but
Sheet 1 will also notice the cell change and try to mirror Sheet2
and vice versa, on and on and on???

What do you think?

"Mike Fogleman" wrote in message
...

In sheet1 code module put this:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheet2.Range(Target.Address).Value = Target.Value
End Sub

in Sheet2 code module this:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheet1.Range(Target.Address).Value = Target.Value
End Sub






Mike Fogleman[_2_]

sheets that mirror each other
 
Let me study this once more. There must be a way, maybe with an IF
statement.

Mike F
"Robert Crandal" wrote in message
...
Try putting a MsgBox("Im in Sheet1") statement in the
Worksheet_Change() function for sheet1. It will
give you about 45 message boxes/dialog boxes that
say "I'm in Sheet1". It appears that Excel runs out of
stack space at that point.

so it appears that the Change event is triggered in the
other sheets as well.

"Mike Fogleman" wrote in message
...
It worked OK on my test sheets. This assigns a value to a cell and does
not trigger the Change event in the other sheet. Editing the cell does,
but only for that sheet.

Mike F
"Robert Crandal" wrote in message
...
Wouldn't this cause an infinite loop or something???
Sheet2 will try to mirror the contents of Sheet 1, but
Sheet 1 will also notice the cell change and try to mirror Sheet2
and vice versa, on and on and on???

What do you think?

"Mike Fogleman" wrote in message
...

In sheet1 code module put this:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheet2.Range(Target.Address).Value = Target.Value
End Sub

in Sheet2 code module this:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheet1.Range(Target.Address).Value = Target.Value
End Sub








Robert Crandal

sheets that mirror each other
 
How about the following code in the Worksheet_Change()
for Sheet1:

If Application.ActiveSheet.CodeName = "Sheet1" Then
' copy data to Sheet2
End if

Then, in the code for Worksheet_Change() for Sheet2,
use the following:

If Application.ActiveSheet.CodeName = "Sheet2" Then
' copy data to Sheet1
End if

What do you think about that idea??


"Mike Fogleman" wrote in message
...
Let me study this once more. There must be a way, maybe with an IF
statement.

Mike F
"Robert Crandal" wrote in message
...
Try putting a MsgBox("Im in Sheet1") statement in the
Worksheet_Change() function for sheet1. It will
give you about 45 message boxes/dialog boxes that
say "I'm in Sheet1". It appears that Excel runs out of
stack space at that point.



Mike Fogleman[_2_]

sheets that mirror each other
 
Yes, that seems to do it:
sheet1 code

Private Sub Worksheet_Change(ByVal Target As Range)
If Application.ActiveSheet.CodeName = "Sheet1" Then
Sheet2.Range(Target.Address).Value = Target.Value
Else
Exit Sub
End If
'MsgBox ("Im in Sheet1")
End Sub

sheet2 code

Private Sub Worksheet_Change(ByVal Target As Range)
If Application.ActiveSheet.CodeName = "Sheet2" Then
Sheet1.Range(Target.Address).Value = Target.Value
Else
Exit Sub
End If
'MsgBox ("Im in Sheet2")
End Sub

Mike F
"Robert Crandal" wrote in message
...
How about the following code in the Worksheet_Change()
for Sheet1:

If Application.ActiveSheet.CodeName = "Sheet1" Then
' copy data to Sheet2
End if

Then, in the code for Worksheet_Change() for Sheet2,
use the following:

If Application.ActiveSheet.CodeName = "Sheet2" Then
' copy data to Sheet1
End if

What do you think about that idea??


"Mike Fogleman" wrote in message
...
Let me study this once more. There must be a way, maybe with an IF
statement.

Mike F
"Robert Crandal" wrote in message
...
Try putting a MsgBox("Im in Sheet1") statement in the
Worksheet_Change() function for sheet1. It will
give you about 45 message boxes/dialog boxes that
say "I'm in Sheet1". It appears that Excel runs out of
stack space at that point.






All times are GMT +1. The time now is 07:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com