• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

code to make two cells have the same value

carics

Member
Hello,


I am looking for a way to have cells A1 in sheet1 and A1 in sheet2 always have the same value.

The action would be:


- both are blank

- I enter number 1 in A1 sheet1 --> A1 in sheet2 gets number 1 as well

- I enter letter a in A1 in sheet2 --> A1 in sheet1 changes from 1 to letter a


How could I have it?
 
Would need 2 change event macros. Right click on sheet 2 tab, view code, paste this in:

[pre]
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Worksheets("Sheet1").Range("A1") = Me.Range("A1")
Application.EnableEvents = True
End Sub
Then, go to the Sheet1 module and paste this in:

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Worksheets("Sheet2").Range("A1") = Me.Range("A1")
Application.EnableEvents = True
End Sub
[/pre]
Note that you may need to change the sheet names to match your exact setup.
 
Luke M that is simply perfect! I am always amazed by VBA ninjas!


Thank you both very much for your replies.
 
Back
Top