+ Reply to Thread
Results 1 to 7 of 7

Mirror range of cells in different sheets?

Hybrid View

fishermanryan Mirror range of cells in... 07-09-2014, 10:43 AM
marreco Re: Mirror range of cells in... 07-09-2014, 10:44 AM
marreco Re: Mirror range of cells in... 07-09-2014, 10:48 AM
GeneralDisarray Re: Mirror range of cells in... 07-09-2014, 10:59 AM
fishermanryan Re: Mirror range of cells in... 07-09-2014, 06:34 PM
GeneralDisarray Re: Mirror range of cells in... 07-09-2014, 11:04 AM
GeneralDisarray Re: Mirror range of cells in... 07-10-2014, 10:56 AM
  1. #1
    Registered User
    Join Date
    07-08-2014
    Location
    Denver, CO
    MS-Off Ver
    2013
    Posts
    7

    Mirror range of cells in different sheets?

    I would like to mirror a range of cells between two sheets in the same workbook, so that if the data is manually input into one of the cells in range (E5:H11) in 'Sheet 1', it is automatically updated in the corresponding cell in (H33:K39) of 'Sheet 2', and vice versa.

    How can I make this happen? More details than not might be helpful since I'm new to VBA.

    Using Office 2013. Thanks!
    Last edited by fishermanryan; 07-14-2014 at 01:10 PM.

  2. #2
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: Mirror range of cells in different sheets?

    It same post
    http://www.mrexcel.com/forum/excel-q...nt-sheets.html
    "No xadrez nem sempre a menor dist?ncia entre dois pontos ? uma linha reta" G. Kasparov.

    If your problem is solved, please say so clearly, and mark your thread as Solved: Click the Edit button on your first post in the thread, Click Go Advanced, select b from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Edit button will not appear -- ask a moderator to mark it.

  3. #3
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: Mirror range of cells in different sheets?

    Try this
    Sub Mirror()
        Worksheets("Sheet2").Range("H33:K39").Value = Worksheets("Sheet1").Range("E5:H11").Value
    End Sub

  4. #4
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Mirror range of cells in different sheets?

    See attached solution - this is what I did:

    1- Name the areas you want to sync (I named them area_1 and area_2)

    2- Use worksheet_change() events on both sheets to control what happens when one sheet is altered.

    code for worksheet 1:
    Option Explicit
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim colNum As Long, rowNum As Long
    
        If Not Intersect(Target, [area_1]) Is Nothing Then
          colNum = Target.Column - [area_1].Cells(1, 1).Column + 1
          rowNum = Target.Row - [area_1].Cells(1, 1).Row + 1
          
          Application.EnableEvents = False
          [area_2].Cells(rowNum, colNum).Value = Target.Value
        End If
        
        Application.EnableEvents = True
    End Sub


    code for worksheet 2:

    Option Explicit
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim colNum As Long, rowNum As Long
    
        If Not Intersect(Target, [area_2]) Is Nothing Then
          colNum = Target.Column - [area_2].Cells(1, 1).Column + 1
          rowNum = Target.Row - [area_2].Cells(1, 1).Row + 1
          
          Application.EnableEvents = False
          [area_1].Cells(rowNum, colNum).Value = Target.Value
        End If
        
        Application.EnableEvents = True
    End Sub
    Attached Files Attached Files
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  5. #5
    Registered User
    Join Date
    07-08-2014
    Location
    Denver, CO
    MS-Off Ver
    2013
    Posts
    7

    Re: Mirror range of cells in different sheets?

    Quote Originally Posted by GeneralDisarray View Post
    See attached solution - this is what I did:

    1- Name the areas you want to sync (I named them area_1 and area_2)

    2- Use worksheet_change() events on both sheets to control what happens when one sheet is altered.

    code for worksheet 1:
    Option Explicit
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim colNum As Long, rowNum As Long
    
        If Not Intersect(Target, [area_1]) Is Nothing Then
          colNum = Target.Column - [area_1].Cells(1, 1).Column + 1
          rowNum = Target.Row - [area_1].Cells(1, 1).Row + 1
          
          Application.EnableEvents = False
          [area_2].Cells(rowNum, colNum).Value = Target.Value
        End If
        
        Application.EnableEvents = True
    End Sub


    code for worksheet 2:

    Option Explicit
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim colNum As Long, rowNum As Long
    
        If Not Intersect(Target, [area_2]) Is Nothing Then
          colNum = Target.Column - [area_2].Cells(1, 1).Column + 1
          rowNum = Target.Row - [area_2].Cells(1, 1).Row + 1
          
          Application.EnableEvents = False
          [area_1].Cells(rowNum, colNum).Value = Target.Value
        End If
        
        Application.EnableEvents = True
    End Sub
    Worked like a charm, thank you. I'm having problems with editing multiple cells at once. If I paste values into multiple cells, or delete multiple cells, only one cell on the mirrored range is changed. Any idea how to fix this?

  6. #6
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Mirror range of cells in different sheets?

    Huh, i guess you could just mirror the entire table each time like marreco is showing - but you'll still need to "fire" that command when a worksheet change is made. You can leave in the control "If Not Intersect(Target, [area_2]) Is Nothing Then" just to keep it from firing when a change is made to other parts of the worksheet (outside of the tables you mentioned).

  7. #7
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Mirror range of cells in different sheets?

    hmm. Well that's interesting.

    I think we could just borrow from marreco's idea and mirror the entire table each time.

    The problem is with this line: [area_1].Cells(rowNum, colNum).Value = Target.Value

    [area_1].Cells(rowNum, colNum) is always one cell, where Target (as you just pointed out) can me many cells.

    All we need to do is equate the values for the areas - we still need to control each event so it happens both directions, and we need to toggle application events on and off to avoid being stuck in a loop. But the code should just look like this:

    Option Explicit
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim colNum As Long, rowNum As Long
    
        If Not Intersect(Target, [area_2]) Is Nothing Then
            Application.EnableEvents = False
            [area_1].Value = [area_2].Value
        End If
        
        Application.EnableEvents = True
    End Sub
    Attached Files Attached Files

+ 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. Mirror Data between Sheets
    By brittarees in forum Excel General
    Replies: 3
    Last Post: 11-04-2013, 05:23 PM
  2. Master Sheet to Mirror Designated Sub Sheets
    By TJetset in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-03-2013, 08:14 PM
  3. [SOLVED] how to create mirror copy of sheets
    By amarjeet.it in forum Excel General
    Replies: 5
    Last Post: 03-09-2013, 09:17 AM
  4. Mirror row deleting on multiple sheets.
    By MarVil85 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-20-2012, 02:59 PM
  5. Mirror multiple cells in different sheets
    By abarney in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-18-2012, 03:13 PM

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