+ Reply to Thread
Results 1 to 16 of 16

Copy Range from Workbook2 to Workbook Problem

  1. #1
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141

    Copy Range from Workbook2 to Workbook Problem

    Dear Sirs,

    I've very much frustrated with the copy and paste problem, as I've been trying different ways but still fails :

    1. Every month, I've to copy and paste a row of forecast data from a number of files (source) to a master file (target).
    2. Both source and target file have the same password locking sheet1, and sheet1's Tab name will change every month
    3. Since the Master file and Souce file will change file names from time to time, my macro has to use Workbook(1) as Master file (first open file) and Workbook(2) as Source file (second open file)

    My codes are :
    Please Login or Register  to view this content.
    The codes can finish to the end, but cannot see the pasted result (ie just nothing copied to the Master file)
    It seems the password protection may cause the issue, but do not know how to modify.

    Hope someone could kindly advise.

    Many thanks indeed.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    12-30-2020
    Location
    Odessa / Ukraine
    MS-Off Ver
    2021
    Posts
    301

    Re: Copy Range from Workbook2 to Workbook Problem

    Quote Originally Posted by chasoe View Post
    my macro has to use Workbook(1)
    Hello. Can you attach the file you are copying from? The original is optional, the main thing is that the structure should be identical. Or is it identical to the Receipt Forecast -MasterFile.xlsm‎ that you attached to your Thread?

  3. #3
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Copy Range from Workbook2 to Workbook Problem

    The purpose of the macro is to copy the value of the complete row of the selected cell from the source file and paste them to the destination file at the at the row with same code project.
    Sheets concerned are always the first one in the source and destination file.
    Is it, please confirm
    - Battle without fear gives no glory - Just try

  4. #4
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Copy Range from Workbook2 to Workbook Problem

    HI everybody,

    I now re-upload the Master file and the Source file.

    My intended procedure is :
    1. Open Master file (destination file-workbook1), then the Source file (workbook2), both files are identical in structure, and "sheet1" code sheet name refer the same first sheet in the 2 files.
    2. Place cursor in Source file (sheet1) on any cell in the project row with forecast data, and execute the copy forecast macro
    3. The macro will first get the project code in column A of Source file (copy the whole row), and then lookup the corresponding project code row in Master file for pasting by formula
    4. Since workbook1 & workbook2, and also sheet1 code sheet name, will change each month, the codes cannot use the actual file name and sheet name
    5. To avoid the Source file being tampered with in sheet structure, password protection is required

    Perhaps I'm not properly trained in progamming (the codes are often built up by looking up the internet), there should have been some syntax error in the codes which throw up errors again and again.
    Errors occur include not recognizing the use of "sheet1", or stuck while pasting, or nothing being pasted after finishing the codes(may be due to "display alert = false"

    So it looks to me a simple operation of copy and paste, but turn out a difficuilt task for me.

    See if anyone could help spot out the problems in the codes.

    Many thanks again.

  5. #5
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Copy Range from Workbook2 to Workbook Problem

    What about the Special Paste ... it seems you want to copy-paste only values is it ??

  6. #6
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141
    Quote Originally Posted by PCI View Post
    What about the Special Paste ... it seems you want to copy-paste only values is it ??
    I need to paste formulas, because some cells have to retain cell formulas linking adjacent cells.

  7. #7
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Copy Range from Workbook2 to Workbook Problem

    Is it clear that some names are in error: JVList
    and the formula result will give empty

  8. #8
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Copy Range from Workbook2 to Workbook Problem

    The error in JVList should not be the cause in copy and paste error.

    To dispose this doubt, I remove all the range names errors as well as removing any formula linkages to JVList, and upload the files again.

  9. #9
    Valued Forum Contributor
    Join Date
    12-30-2020
    Location
    Odessa / Ukraine
    MS-Off Ver
    2021
    Posts
    301

    Re: Copy Range from Workbook2 to Workbook Problem

    Hello @chasoe.
    Maybe so you need, did not quite understand what you need exactly? Try.
    Please Login or Register  to view this content.
    Last edited by MikeVol; 07-17-2023 at 07:54 AM. Reason: Update

  10. #10
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Copy Range from Workbook2 to Workbook Problem

    Is it what you need ?

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Copy Range from Workbook2 to Workbook Problem

    Let me take some time to test.

  12. #12
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Copy Range from Workbook2 to Workbook Problem

    Hi, thanks for all your kind feebacks.

    I've tested.

    For @PCI's codes : It works fine, but I think the line "DstRg.NumberFormat = "General" has rendered some date field column to become a numeric figure (instead of in date format), and numeric fields do not show thousand separators with 2 decimal places which I find it difficult to fix. This is why in my original codes, I would rather paste formulas.

    For @MikeVol codes : It stuck in the line ".Find(What:=PCode, After:=ActiveCell, LookIn:=xlValues," for unknown reason (this line seems no error)

    In fact, by many trials and errors, I amended my codes which seems to work fine to me (although may not be an orthodox way for a professional programmer, as I often declare NOT enough memory variables)

    Please Login or Register  to view this content.
    I attach revised Source & Master files.

    Thank you again.
    Last edited by chasoe; 07-18-2023 at 09:49 PM.

  13. #13
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Copy Range from Workbook2 to Workbook Problem

    Please Login or Register  to view this content.
    Yes just remove it, it was for debuggung option
    Please Login or Register  to view this content.

  14. #14
    Valued Forum Contributor
    Join Date
    12-30-2020
    Location
    Odessa / Ukraine
    MS-Off Ver
    2021
    Posts
    301

    Re: Copy Range from Workbook2 to Workbook Problem

    Hello @chasoe.
    What would you say?
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Copy Range from Workbook2 to Workbook Problem

    Hello,

    I've tested both revised codes from @PCI and @MikeVol, both work fine.

    Since there are advanced codes which I cannot fully understand, so there may be problem in future if modification is required due to changes in the file structure, although I hope I can find time to learn more.

    Anyway, many thanks indeed for your untiring efforts.

  16. #16
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Copy Range from Workbook2 to Workbook Problem

    there are advanced codes which I cannot fully understand
    Humm, not sure, the code is really simple and doing not to much: No grouping etc ..
    But do as you feel it.
    Thank you for the Rep
    Enjoy Excel

+ 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. Replies: 0
    Last Post: 10-29-2022, 04:40 PM
  2. [SOLVED] Copy rows from Workbook 1 to Workbook2 if condition is met
    By Xsample in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 03-01-2018, 10:24 AM
  3. [SOLVED] Copy cells from selected range of workbook1 to the first empty row in a table in workbook2
    By mab.alianza.ez8 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-11-2017, 04:09 AM
  4. Find value from Workbook1 in Workbook2, HOffset and copy range data
    By Dill Pickle in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-17-2016, 09:46 PM
  5. VBA code to make of copy of workbook2 and then copy data in that from Workbook1
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-05-2015, 06:34 AM
  6. How to bring data from workbook1 to workbook2 by comparing values of workbook2
    By amethystfeb in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-04-2013, 09:38 AM
  7. Data from workbook1 to workbook2 every week but in different place in workbook2
    By cheelie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-29-2007, 06:26 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