Bi-directional (two-way) Link in Excel using cells in multiple rows and columns

louperrotta

New Member
Joined
Jul 30, 2024
Messages
20
Office Version
  1. 365
Platform
  1. Windows
As of right now I can only get it to work with one cell to one cell, not multiple but I am very much a layman...here is what I was using:

VBA Code:
Private Sub Worksheet_change(ByVal Target As Range)

If Not Intersect(Target, Range("A1")) Is Nothing Then
   If Target = Range("A1") Then
      Sheets("Sheet2").Range("B1").Value = Target.Value
   End If
End If

End Sub


Private Sub Worksheet_change(ByVal Target As Range)

If Not Intersect(Target, Range("B1")) Is Nothing Then
  If Target = Range("B1") Then
    If Sheets("Sheet1").Range("A1").Value <> Target.Value Then
      Sheets("Sheet1").Range("A1").Value = Target.Value
    End If
  End If
End If

End Sub

So when I tried to use (A1:A20) & (B1:B20) it was error...what am I doing wrong? Hahaha, again, I'm a layman! Here:

VBA Code:
Private Sub Worksheet_change(ByVal Target As Range)

If Not Intersect(Target, Range("A1:A20")) Is Nothing Then
   If Target = Range("A1:A20") Then
      Sheets("Sheet2").Range("B1:B20").Value = Target.Value
   End If
End If

End Sub


Private Sub Worksheet_change(ByVal Target As Range)

If Not Intersect(Target, Range("B1:B20")) Is Nothing Then
  If Target = Range("B1:B20") Then
    If Sheets("Sheet1").Range("A1:A20").Value <> Target.Value Then
      Sheets("Sheet1").Range("A1:A20").Value = Target.Value
    End If
  End If
End If

End Sub

Thank you so much! You are all amazing!! Hope you can help! :)
 
Last edited by a moderator:
Yes, the code belongs in the ThisWorkbook module.

If the code is not running, it could be because you have Application.EnableEvents = False, because the code you were using errored before resetting Application.EnableEvents = True.

In the Immediate Window, try typing Application.EnableEvents = True and then retry making changes.

If you can't see the Immediate Window in the VB Editor, select View/Immediate Window or type CTRL+G.
Huh, yeah, I put

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

Dim i As Long
Dim rng1 As Range, rng2 As Range

Application.EnableEvents = False

For i = 2 To 4 'Assumes Sheet 1 <---> Sheets 2,3,4. Extend if you wish
Set rng1 = Worksheets("Sheet1").Range("A1:C20").Offset(20 * (i - 2))
Set rng2 = Worksheets("Sheet" & i).Range("A1:C20").Offset(20 * (i - 2))
If Target.Worksheet.Name = "Sheet1" Then
If Not Intersect(Target, rng1) Is Nothing Then rng2.Value = rng1.Value
ElseIf Target.Worksheet.Name = "Sheet" & i Then
If Not Intersect(Target, rng2) Is Nothing Then rng1.Value = rng2.Value
End If
Next i

Application.EnableEvents = True

End Sub

and then Application.EnableEvents = True in the Immediate Window but still nothing...it's so weird...
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Yes, the code belongs in the ThisWorkbook module.

If the code is not running, it could be because you have Application.EnableEvents = False, because the code you were using errored before resetting Application.EnableEvents = True.

In the Immediate Window, try typing Application.EnableEvents = True and then retry making changes.

If you can't see the Immediate Window in the VB Editor, select View/Immediate Window or type CTRL+G.
 

Attachments

  • Screenshot (8).png
    Screenshot (8).png
    205.1 KB · Views: 5
Upvote 0
So, I downloaded the file and it has that same formula in it but when I type stuff in the A Column nothing shows up, I don't get it, so weird...I just don't understand why it is not working....
 

Attachments

  • Screenshot (10).png
    Screenshot (10).png
    210.4 KB · Views: 2
  • Screenshot (11).png
    Screenshot (11).png
    207.5 KB · Views: 2
  • Screenshot (12).png
    Screenshot (12).png
    207.8 KB · Views: 2
  • Screenshot (13).png
    Screenshot (13).png
    209.1 KB · Views: 2
Upvote 0
I can't see any obvious problems, based on the picture you've posted.

Give this a try. It works fine for me: Links.xlsm
So, I downloaded the file and it has that same formula in it but when I type stuff in the A Column nothing shows up, I don't get it, so weird...I just don't understand why it is not working....
 

Attachments

  • Screenshot (10).png
    Screenshot (10).png
    210.4 KB · Views: 4
  • Screenshot (11).png
    Screenshot (11).png
    207.5 KB · Views: 2
  • Screenshot (12).png
    Screenshot (12).png
    207.8 KB · Views: 2
  • Screenshot (13).png
    Screenshot (13).png
    209.1 KB · Views: 2
Upvote 0
Do you have macros enabled?

If you put a breakpoint in Sub Workbook_SheetChange, can you step through and see what's happening?
 
Upvote 0
Do you have macros enabled?

If you put a breakpoint in Sub Workbook_SheetChange, can you step through and see what's happening?
So I enabled macros but I'm still lost on the breakpoint, for some reason the code is just not working, because I should be able to type data in Sheet 1 and it appears in sheets 2, 3, etc. correct? **** dude I'm sorry, I just don't know why it's not working once I download it...****...
 

Attachments

  • Screenshot (14).png
    Screenshot (14).png
    227.6 KB · Views: 5
Upvote 0
but I'm still lost on the breakpoint ...
I'm not sure what you mean by this?

If you put a breakpoint at the top of Sub Workbook_SheetChange and change any cell in the workbook, the macro should stop at the breakpoint, so that you can step throught the code line by line (using F8 key) to see what's happening.

But it sounds like your code isn't running at all? Can you create and run any macro?

VBA Code:
'In a code Module
Sub Hello()

    MsgBox "Hello!"
   
End Sub
 
Upvote 0
I'm not sure what you mean by this?

If you put a breakpoint at the top of Sub Workbook_SheetChange and change any cell in the workbook, the macro should stop at the breakpoint, so that you can step throught the code line by line (using F8 key) to see what's happening.

But it sounds like your code isn't running at all? Can you create and run any macro?

VBA Code:
'In a code Module
Sub Hello()

    MsgBox "Hello!"
  
End Sub
Hey! Hahaha, I'm an idiot, I typed the code in wrong (I'm trying to type it out to practice typing stuff in instead of copy an paste haha) and then when I typed it in correctly on a new book, I accidently did have macros on lol, I feel like an idiot. But I finally got the macros working! YAY! Thank you so much for dealing with me! You are so awesome man!

May I ask one more thing?

May I ask how the code you wrote actually works? Like how you wrote it the way you did, what makes it work, and how VPNs work in general? Again, no pressure, I'm just wondering! I'm starting some tutorials! :) How long have you been working with excel?
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,127
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top