VBA 1 cell linked between 3 sheets work but a second cell doesnt

Metaripley

Board Regular
Joined
Dec 31, 2014
Messages
93
Hi!

Ive got a code running in my sheets codes where in Sheet 1, sheet 2 and sheet 3 have a cell that when you change 1 the other 2 also change.
Now I want to ad a second cell on each sheet that does the same.
But I cant get it to work.

This is the working code for the first cell.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)



    Dim KeyCells As Range
    Application.EnableEvents = False




' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
    Set KeyCells = Range("C2")


    If Not Application.Intersect(KeyCells, Range(Target.Address)) _
    Is Nothing Then


' Display a message when one of the designated cells has been
' changed.
    Worksheets("TS - VS").Range("B1").Value = KeyCells.Value
    Worksheets("Isolated HS - HSS").Range("B1").Value = KeyCells.Value
    Worksheets("Parameters Production").Range("C2").Value = KeyCells.Value
    
    End If
    Application.EnableEvents = True


End Sub

Now I want to add cell C3 on "Parameters Production" and C2 on "TS - VS".

I already tried adding a complete new Sub below the working one and to add another Dim Range within the working one.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Now I want to add cell C3 on "Parameters Production" and C2 on "TS - VS".

I don't follow what that means.

The example code below uses an ElseIf for the 2nd cell.
Though I don't think it changes the correct cells on the other sheets. Perhaps it's enough for you to figure out.


Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] Worksheet_Change([COLOR=darkblue]ByVal[/COLOR] Target [COLOR=darkblue]As[/COLOR] Range)
    
    Application.EnableEvents = [COLOR=darkblue]False[/COLOR]
    
    [COLOR=darkblue]If[/COLOR] Target.Address(0, 0) = "C2" [COLOR=darkblue]Then[/COLOR]
        [COLOR=green]' Display a message when one of the designated cells has been[/COLOR]
        [COLOR=green]' changed.[/COLOR]
            Worksheets("TS - VS").Range("B1").Value = Target.Value
            Worksheets("Isolated HS - HSS").Range("B1").Value = Target.Value
            Worksheets("Parameters Production").Range("C2").Value = Target.Value
    
    [COLOR=darkblue]ElseIf[/COLOR] Target.Address(0, 0) = "C3" [COLOR=darkblue]Then[/COLOR]
        [COLOR=green]' Display a message when one of the designated cells has been[/COLOR]
        [COLOR=green]' changed.[/COLOR]
            Worksheets("TS - VS").Range("B2").Value = Target.Value
            Worksheets("Isolated HS - HSS").Range("B2").Value = Target.Value
            Worksheets("Parameters Production").Range("C3").Value = Target.Value
    
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    
    Application.EnableEvents = [COLOR=darkblue]True[/COLOR]
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Last edited:
Upvote 0
I don't follow what that means.

Sheet 1: Parameteers Production "C2" and sheet 2: TS-VS "B1" are linked.
Sow when I change C2, B1 on sheet 2 also changes.
If i change B1 then on sheet 1 C2 changes.

Now I want the same for C3 on sheet 1 and C1 on sheet 2.

With the ElsIf added it works one way. From sheet 1 to sheet 2 and 3.
But not back. WHen I change sheet 2 or 3 the other sheets dont change.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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