+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    03-03-2010
    Location
    Oxfordshire
    MS-Off Ver
    Excel 2007
    Posts
    16

    VBA Code To Mirror Cells from one Worksheet to another

    I am quite new to this forum so I apologise if I do something incorrectly.

    I need to mirror individual cells from one worksheet to a multiple of other worksheets within the same work book. I was wondering if anyone had written a code that could do this that I could copy and paste in and edit to fit this document.

    I have had a reasonable look through the forum for this answer but cant seem to find one that fits.

    Thank-you,

    Daniel1234
    Last edited by Daniel1234; 03-05-2010 at 07:06 AM.

  2. #2
    Forum Guru 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Vienna, VA, USA
    MS-Off Ver
    Excel 2003, 2007
    Posts
    2,242

    Re: VBA Code To Mirror Cells from one Worksheet to another

    This is a fairly simple-minded version but works:
    Code:
    Public Sub Worksheet_Change(ByVal Target As Range)
       MirrorCells
    End Sub
    Public Sub MirrorCells()
       Dim DestinationWS As Variant
       DestinationWS = Array("sheet A", "sheet B") ' sheet names where you want the data to be copied
       Dim wsName As Variant
     
       For Each wsName In DestinationWS
          Worksheets(wsName).Range("A1") = Range("A1")
          ' repeat above line for each cell you want to copy
       Next wsName
    End Sub
    This code must go in the code for the worksheet that is the source of the data. I took you literally when you said "mirror"--this puts values in the same cell in the destination that is used in the source.

    Further, this code will copy all of the values of interest every time there is any change anywhere on the source sheet, even if the change is not one of the values to be copied. It is not difficult to make that more efficient but I didn't want to write a lot more code without knowing the specifics of your situation.

    (Also, note that you posted to the Excel General forum, but are asking about VBA code. There is a forum specifically for that called Excel Programming.)
    Making the world a better place one fret at a time
    ||||||

    If someone helped you, please click on the star icon at the bottom of their post

    If your problem is solved, please update the first post:
    EDIT, Go Advanced button, set Prefix to SOLVED

    [code]
    ' Enclose code in tags like this
    [/code]

    Don't attach a screenshot
    --just attach your Excel file! It's easier and will let us experiment with your data, formulas, and code.

  3. #3
    Registered User
    Join Date
    03-03-2010
    Location
    Oxfordshire
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: VBA Code To Mirror Cells from one Worksheet to another

    When i pop it into the view code section i get this error

    Run Time error '9'
    Subscript out of Range

    if i click on debug this line is highlighted in yellow


    Worksheets(wsName).Range("A1") = Range("A1")

    (Sorry for posting in the wrong section will make sure it doesnt happen again)

    Thanks,

    Daniel1234

  4. #4
    Registered User
    Join Date
    03-03-2010
    Location
    Oxfordshire
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: VBA Code To Mirror Cells from one Worksheet to another

    Hi sorry have worked out where i went wrong i needed to put a space inbetween sheet and 1 works like a charm thankyou so much

    Daniel1234

Thread Information

Users Browsing this Thread

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

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.2.0