+ Reply to Thread
Results 1 to 5 of 5

Compare to workbooks, and copy certain values if they have the same worksheetname

  1. #1
    Forum Contributor
    Join Date
    03-09-2010
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2003
    Posts
    173

    Compare to workbooks, and copy certain values if they have the same worksheetname

    Hi,

    I want to write a macro that does the following:
    Compare workbook "A" to workbook "B".
    Define a list of worksheetnames, for instance "C 01.00", "C 02.00".
    If both A and B has the worksheet "C 01.00", then copy values from
    Cell A1, B14, D11 from workbook A and paste it into same worskheet same cells in Workbook B.

    I have to be able to define which cells to be copied given each worksheet.

    Thanks!

    Henrik

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Compare to workbooks, and copy certain values if they have the same worksheetname

    Hi, Henrik ,

    you would need to inform us where the code is to be located and if the workbooks are open or need to be opened.

    This code assumes both workbooks to be open in one instance of Excel:
    Please Login or Register  to view this content.
    In case of multiple areas to copy I would suggest to use a table in a worksheet to store the information.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor
    Join Date
    03-09-2010
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2003
    Posts
    173

    Re: Compare to workbooks, and copy certain values if they have the same worksheetname

    Hi again,

    Thank you - this looks like the start of something.
    The two workbooks are open, thats fine. I can handle the location of the code. I need help with the more advanced part

    The workbook A and B are the same, the only difference is that some of the cells are protected for writing i workbook B (containing calculations etc). Is it from a to b, given that it is allowed by the workbook and that the worksheetname is the same?

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Compare to workbooks, and copy certain values if they have the same worksheetname

    Hi, Henrik,

    I havben´t considered the protection as it wasn´t mentioned (you could add a line to unprotect, run the copy part, protect the sheet again or have a look at the parameter UserInterfaceOnly within protect). You would need to give some information on how many different ranges for sheets you will have.

    The code is designed to copy from wokbook B to workbook A by direct copying of values, not formulas.

    HTH,
    Holger

  5. #5
    Forum Contributor
    Join Date
    03-09-2010
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2003
    Posts
    173

    Re: Compare to workbooks, and copy certain values if they have the same worksheetname

    Hi Holger,

    Thank you for your quick replies. As a wrote in the start:
    "I have to be able to define which cells to be copied given each worksheet."
    If I can define which cells to be copied, given that it is a different set of cells for each worksheet, then I don't have to unprotect the worksheet (I don't have the rights to do it).

    I am not sure if I understood what you needed more info about:
    The workbook contains approx 20 sheets, with different cells to be copied.

    Cheers,
    Henrik

+ 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. [SOLVED] How to compare two string in two different workbooks and Copy the relevant values & Paste?
    By somani123 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-13-2014, 06:47 AM
  2. Compare the cell values in two different workbooks and copy values from one to the other
    By BettyBoop64 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-10-2012, 04:48 PM
  3. Macro to compare values in different workbooks and copy paste adjuscent cells
    By Arjunling in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-05-2012, 07:53 AM
  4. Compare workbooks, if match is found copy values from one to the other
    By XLVBA in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-10-2012, 09:13 AM
  5. Compare and copy details between 2 workbooks
    By xmoore in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 01-12-2010, 05:18 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