+ Reply to Thread
Results 1 to 5 of 5

Linking Two Cells from Different Sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    07-08-2021
    Location
    St. Catharines, Ontario
    MS-Off Ver
    MS365
    Posts
    2

    Linking Two Cells from Different Sheets

    Hello I have very recently just started coding VBA. I am currently trying to make it so I can link two cells from different sheets together, so they will always be the same and update no matter which I edit. Specifically trying to get Cell A11 on sheet 1 to link with Cell B18 on sheet 2. I have code that works on the same page, however I cannot get it to work across sheets. The code I am currently using looks like this:


    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    
    
    If Target.Address = "$S$1" Then
    Application.EnableEvents = False
    Range("$T$1") = Range("$S$1").Value
    ElseIf Target.Address = "$T$1" Then
    Range("$S$1") = Range("$T$1").Value
    Application.EnableEvents = True
    End If
    End Sub
    If anyone could give me tips on how I could set it up to have one cell on sheet 1 and one cell on sheet 2 I would appreciate it a lot! Thank you!
    Last edited by ewansykz; 07-12-2021 at 10:42 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,790

    Re: Linking Two Cells from Different Sheets

    Administrative Note:

    Welcome to the forum.

    Your Excel version will be MS365, not 2106 - please update this in your profile.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code] [/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. As you are new, I have done it for you today.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: Linking Two Cells from Different Sheets

    Try:

    Option Explicit
    
    ' This code goes in the Workbook Class Module
    
    'Hello I have very recently just started coding VBA. I am currently trying to make it
    'so I can link two cells from different sheets together, so they will always be the
    'same and update no matter which I edit. Specifically trying to get Cell A11 on sheet 1
    'to link with Cell B18 on sheet 2. I have code that works on the same page, however I
    'cannot get it to work across sheets. The code I am currently using looks like this:
    
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
    Dim sh1 As Worksheet, sh2 As Worksheet
    Set sh1 = Sheet1: Set sh2 = Sheet2
    
    If Target.Count > 1 Then Exit Sub
    
    Application.EnableEvents = False
    If Sh.Name = sh1.Name And Target.Address = "$A$11" Then
        sh2.Range("$B$18") = sh1.Range("$A$11").Value
    ElseIf Sh.Name = sh2.Name And Target.Address = "$B$18" Then
        sh1.Range("$A$11") = sh2.Range("$B$18")
    End If
    Application.EnableEvents = True
    
    End Sub
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: Linking Two Cells from Different Sheets

    Thanks for the rep.

    Just for consistency …

    Option Explicit
    
    ' This code goes in the Workbook Class Module
    
    'Hello I have very recently just started coding VBA. I am currently trying to make it
    'so I can link two cells from different sheets together, so they will always be the
    'same and update no matter which I edit. Specifically trying to get Cell A11 on sheet 1
    'to link with Cell B18 on sheet 2. I have code that works on the same page, however I
    'cannot get it to work across sheets. The code I am currently using looks like this:
    
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
    Dim sh1 As Worksheet, sh2 As Worksheet
    Set sh1 = Sheet1: Set sh2 = Sheet2
    
    If Target.Count > 1 Then Exit Sub
    
    Application.EnableEvents = False
    If Sh.Name = sh1.Name And Target.Address = "$A$11" Then
        sh2.Range("$B$18").Value = sh1.Range("$A$11").Value
    ElseIf Sh.Name = sh2.Name And Target.Address = "$B$18" Then
        sh1.Range("$A$11").Value = sh2.Range("$B$18").Value
    End If
    Application.EnableEvents = True
    
    End Sub

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: Linking Two Cells from Different Sheets

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. linking sheets against cells VBA
    By louis1357 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-19-2016, 08:57 AM
  2. Linking Cells in Different Sheets with Different Layouts
    By TinyShiny in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-22-2014, 02:13 PM
  3. [SOLVED] Linking particular cells in different sheets
    By VerkaSerduchka in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-26-2014, 02:01 PM
  4. Linking cells in different sheets
    By tailwagsdog in forum Excel General
    Replies: 1
    Last Post: 10-26-2013, 05:27 AM
  5. Linking Sheets and Cells
    By pazzuzu in forum Excel General
    Replies: 2
    Last Post: 01-20-2010, 11:36 AM
  6. Linking 2 cells in different sheets
    By SEF in forum Excel General
    Replies: 1
    Last Post: 03-28-2008, 12:09 PM
  7. Linking two sheets and cells
    By skylinekiller in forum Excel General
    Replies: 0
    Last Post: 01-10-2008, 03:59 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1