+ Reply to Thread
Results 1 to 9 of 9

VBA for copy/paste from file X to current file

  1. #1
    Registered User
    Join Date
    12-31-2021
    Location
    Europe
    MS-Off Ver
    365 version 2111
    Posts
    15

    VBA for copy/paste from file X to current file

    Good morning,

    Not being a 'knower' of VBA would it be possible someone could give me a code to replace the following indirect formulas?
    If the code could be programmed to run on on Friday morning when the file is opened for the first time that would be great (in order to save ressources running every time the file opens).
    The problem is the classic with indirect - it doesnt work with a closed workbook, hence the need for a code.

    The code is to bring the results of last week into this weeks file to compare the progress.
    The source workbook called w(x-1).xlsm is in the same network file (w(x).xlsm) as the destination file and changes every week from w1 to w2 to w3 etc, where the week number is driven by cell S17. This week being w2 and last week being w1 for example.

    File w(x) Cell T17=INDIRECT("[w"&$S$17&".xlsm]Results!$T$101")
    File w(x) Cell T18=INDIRECT("[w"&$S$17&".xlsm]Results!$T$100")
    File w(x) Cell T19=INDIRECT("[w"&$S$17&".xlsm]Results!$T$98")
    File w(x) Cell T20=INDIRECT("[w"&$S$17&".xlsm]Results!$T$99")
    File w(x) Cell T22=INDIRECT("[w"&$S$17&".xlsm]Soot!$F$21")
    File w(x) Cell T23=INDIRECT("[w"&$S$17&".xlsm]Soot!$G$23")

    The result should be inserted as a value.

    Thankyou very much if anyone could help.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,758

    Re: VBA for copy/paste from file X to current file

    If you want the results inserted as values then the VBA will have to open the file anyway to read it. Perhaps your VBA could update the formulas to be direct references:

    Please Login or Register  to view this content.
    and so forth
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    12-31-2021
    Location
    Europe
    MS-Off Ver
    365 version 2111
    Posts
    15

    Re: VBA for copy/paste from file X to current file

    Good morning.

    Would someone be able to suggest a code?

    Thanks

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,758

    Re: VBA for copy/paste from file X to current file

    I suggested code, for the first cell. You just need to copy that line of code and update for each cell.

  5. #5
    Registered User
    Join Date
    12-31-2021
    Location
    Europe
    MS-Off Ver
    365 version 2111
    Posts
    15

    Re: VBA for copy/paste from file X to current file

    No need to define variables or anything?

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,758

    Re: VBA for copy/paste from file X to current file

    No, you are just converting a formula to a hard link, and the data you need is in other cells. No variables are needed.

  7. #7
    Registered User
    Join Date
    12-31-2021
    Location
    Europe
    MS-Off Ver
    365 version 2111
    Posts
    15

    Re: VBA for copy/paste from file X to current file

    Good morning.

    Thanks for your help.

    I inserted this code through VBA into the sheet where i need the result.
    When I run the compiler I get an error highlighting the "=[w" as an invalid outside procedure.

    I am doing something wrong?
    Sorry but I never used this method so I have no clue how it should be inserted/run etc.


    Thankyou

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,758

    Re: VBA for copy/paste from file X to current file

    OK, I did not realize you had no background at all in VBA.

    Open the VBA editor by hitting ALT-F11. See this page for details.

    Right click on the tree under your file and select Insert Module. You will get a new module called Module1. Double click on it. Put the following code into that module. You did not say what worksheet you want these formulas to go it. This example uses Sheet1 but you will need to change it if it's not right.

    Please Login or Register  to view this content.
    Now you can run InsertFormulas from the Macros list.

  9. #9
    Registered User
    Join Date
    12-31-2021
    Location
    Europe
    MS-Off Ver
    365 version 2111
    Posts
    15

    Re: VBA for copy/paste from file X to current file

    Thanks.
    Perfect.

    Never know what to do at the start of the code 'public' etc.
    Working fine.

+ 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: 02-05-2020, 08:26 PM
  2. [SOLVED] VB Code to copy and paste from all text file and paste into single file
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-29-2015, 06:00 PM
  3. Replies: 3
    Last Post: 05-21-2013, 08:22 AM
  4. Copy data from other files and paste in current file ----really need assistance
    By aetedford in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-02-2013, 05:37 PM
  5. [SOLVED] open variably named file, copy/paste data into consolidation file, open next file in list
    By sllawrence1968 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2012, 09:49 PM
  6. [SOLVED] copy from external file, paste in current workbook
    By rodich in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-16-2012, 04:29 AM
  7. Replies: 1
    Last Post: 10-17-2005, 04:05 AM

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