Bi-directional linking of multiple cells

hazmat

New Member
Joined
Jun 14, 2019
Messages
39
Office Version
  1. 2016
Platform
  1. Windows
Been spinning my wheels on this for a while....
I have the following code that works for bi-directionally linking 2 cells, (on same sheet for now), placed in the Worksheet_Change Sub.
VBA Code:
    If Not Intersect(Target, Range("E8")) Is Nothing Then

            Application.EnableEvents = False
            Range("AE8") = Range("E8")
            Application.EnableEvents = True
    End If

    If Not Intersect(Target, Range("AE8")) Is Nothing Then

            Application.EnableEvents = False
            Range("E8") = Range("AE8")
            Application.EnableEvents = True
    End If

However, I have 150 pairs of cells in multiple, non-contiguous columns, I want to link. I can copy the code for the other 149 pair of cells, but thinking there has got to be a better way to accomplish this.
I need to bi-directionally link the following....
E8:E37, I8:I37, L8:L37, O8:O37, R8:R37, top to bottom, left to right, starting with E8.....with AE8:AE157
Thanks in advance for any and all help.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Rather then code that does not work, explain in a concise manner what you need to happen.
BTW, the jump from E column to I column is 4 while all the others are three. Is that an oversight or reality?
 
Upvote 0
However, I have 150 pairs of cells in multiple, non-contiguous columns, I want to link.
Why on earth would you want to duplicate your user input areas and create these unnecessary overheads?

If you must:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    
    If Not Intersect(Target, Range("AE8:AE157")) Is Nothing Then
        Range("E8:E37").Value = Range("AE8:AE37").Value
        Range("I8:I37").Value = Range("AE38:AE67").Value
        Range("L8:L37").Value = Range("AE68:AE97").Value
        Range("O8:O37").Value = Range("AE98:AE127").Value
        Range("R8:R37").Value = Range("AE128:AE157").Value
    End If

    If Not Intersect(Target, Range("E8:E37,I8:I37,L8:L37,O8:O37,R8:R37")) Is Nothing Then
        Range("AE8:AE37").Value = Range("E8:E37").Value
        Range("AE38:AE67").Value = Range("I8:I37").Value
        Range("AE68:AE97").Value = Range("L8:L37").Value
        Range("AE98:AE127").Value = Range("O8:O37").Value
        Range("AE128:AE1577").Value = Range("R8:R37").Value
    End If

    Application.EnableEvents = True
    Application.ScreenUpdating = True

End Sub

This doesn't allow for the possibility that the user changes both sides of a "link" in one go. It also assumes the user enters only values, and not formulae.
 
Upvote 0
Solution
First, thanks for the help. The code does exactly what i wanted it to do, and gets me 1 step closer to my ultimate goal.
Why on earth would you want to duplicate your user input areas and create these unnecessary overheads?
Good question. Probably because I'm just a dumb old Firefighter, with very limited coding knowledge, and don't know any better, lol

Seriously though, The range ("AE8:AE157") will be hidden, and user will not be able to directly change that data. That data will be changed from user input on another sheet,. (when i figure out how to do that, it will be more than just mirroring the data. I'm sure another request for help will be forthcoming.)

In a nut shell, this is what I'm working on. Right now, I have 3 separate workbooks that tracks overtime. One for each FF's, Lt's and Capt's. All work fine and are basically the same, just the names are changed.
I have combined them into 1 workbook now with 3 sheets, and working on creating a 4th sheet where the user will select names and enter data (dates). The data will be transferred to the corresponding sheet, and that sheet will do it's thing. Although the user SHOULD only be entering data on the 4th sheet, there is the possible situation where the user might have to change data on one of the 3 sheets directly and i want sheet 4 to reflect that data, if that happens.

thanks again
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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