+ Reply to Thread
Results 1 to 21 of 21

Macro to: open workbook, copy multiple values, paste them to another workbook.

  1. #1
    Registered User
    Join Date
    01-26-2020
    Location
    Warsaw, Poland
    MS-Off Ver
    365
    Posts
    28

    Macro to: open workbook, copy multiple values, paste them to another workbook.

    Hey, I need a macro which would open a workbook, copy values which are stored in many different (but always the same) cells and paste it a template also to many different, but always the same cells. Unfortunately it is not possible to move those cells in any of those files to simplify this process. I have a tiny bit of code, but I have no idea how to make it to copy and paste many cells t once. Mine copies either a cell or a range of cells which are grouped together. I'm not adding any example file caus it could work the same way on any 2 workbooks. If any will be needed - I can provide some.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    If there is no relative positioning for all the copy/paste locations, then you'll need to list each pair of cells/ranges. That said, this set-up should make it easier to do so...
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-26-2020
    Location
    Warsaw, Poland
    MS-Off Ver
    365
    Posts
    28

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    Hey, unfortunatelly it's not working. It stops as on attached screen.Attachment 685168

  4. #4
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    Sorry, can't open your attachment.

  5. #5
    Registered User
    Join Date
    01-26-2020
    Location
    Warsaw, Poland
    MS-Off Ver
    365
    Posts
    28

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    Oh, strange. But it stops here: „ With ThisWorkbook.Worksheets("SelectFile")”

  6. #6
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    If the error is "Subcript out of range" then that worksheet was not found in the workbook running the code. Possibly a spelling mistake? or added space?

  7. #7
    Registered User
    Join Date
    01-26-2020
    Location
    Warsaw, Poland
    MS-Off Ver
    365
    Posts
    28

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    Ok, you’re right
    Last edited by maamon; 07-04-2020 at 01:28 PM. Reason: Delete

  8. #8
    Registered User
    Join Date
    01-26-2020
    Location
    Warsaw, Poland
    MS-Off Ver
    365
    Posts
    28

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    OK, I've tested it with the correct name of the sheet now, but it didn't execute copying. Macro went through, original file was opened and closed, but there are no values in the destination file. Cells B11, B13, C12, C14 are empty after the macro finished. In the file I'm trying to copy from those values are calculated formulas. Can it have influence on this?


    Sub Get_Data_From_File()
    Dim FileToOpen As String
    Dim OpenWS As Worksheet


    FileToOpen = Application.GetOpenFilename(Title:="Select calculated PPR and import data to MAGNA OS template", _
    FileFilter:="Excel Files (*.xls*),*xls*")
    If FileToOpen = "False" Then Exit Sub

    Application.ScreenUpdating = False

    Set OpenWS = Workbooks.Open(Filename:=FileToOpen, ReadOnly:=True).Worksheets(1)
    With ThisWorkbook.Worksheets("SelectFile")
    .Range("V24") = OpenWS.Range("B11")
    .Range("V23") = OpenWS.Range("B13")
    .Range("V22") = OpenWS.Range("C12")
    .Range("V29") = OpenWS.Range("C14")
    ' .Range("A10") = OpenWS.Range("V19")
    ' ...List all the data transfers needed

    End With
    OpenWS.Parent.Close False

    Application.ScreenUpdating = True
    End Sub

  9. #9
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    Is the data to be collected on worksheets(1)? (Worksheets(1) is the left-most tab)

  10. #10
    Registered User
    Join Date
    01-26-2020
    Location
    Warsaw, Poland
    MS-Off Ver
    365
    Posts
    28

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    Yes, it is. Well...the name of this worksheet is different.

  11. #11
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    What was the error?

  12. #12
    Registered User
    Join Date
    01-26-2020
    Location
    Warsaw, Poland
    MS-Off Ver
    365
    Posts
    28

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    There was no. It just did nothing apart from opening and closing workbook.

  13. #13
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  14. #14
    Registered User
    Join Date
    01-26-2020
    Location
    Warsaw, Poland
    MS-Off Ver
    365
    Posts
    28

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    Ok, there you go. Two files: "copy_from_here" - I need to extract data from this file, from tab "calculations" and paste it to workbook ""copy_to_this_file". There are tabs "_before" and"after" to visualize what needs to be done. Hope this is clear. Of course as said before this macro has to open and close file "copy_from_here" without saving any changes and paste data as values to the second file.
    Attached Files Attached Files

  15. #15
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    This worked on your sample files...
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    01-26-2020
    Location
    Warsaw, Poland
    MS-Off Ver
    365
    Posts
    28

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    This is very strange. It is not working for me. Please see screenshots attached. I hope it will be visible this time. Error is the same as previously when I've tried to attach screenshots.
    Attached Images Attached Images

  17. #17
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    The code as written needs to be run from the destination workbook. If not, you'll need to replace 'Thisworkbook' with the full name of the workbook containing the code.

  18. #18
    Registered User
    Join Date
    01-26-2020
    Location
    Warsaw, Poland
    MS-Off Ver
    365
    Posts
    28

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    It was run from the destination workbook.

  19. #19
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    Use this file...
    Attached Files Attached Files

  20. #20
    Registered User
    Join Date
    01-26-2020
    Location
    Warsaw, Poland
    MS-Off Ver
    365
    Posts
    28

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    I don' get it, but it worked :o
    Thanks so much. Now will try to apply to my real files.

  21. #21
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Macro to: open workbook, copy multiple values, paste them to another workbook.

    Good luck!

+ 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] Copy and paste data from multiple files into open workbook
    By 1953CAG in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-04-2016, 05:27 AM
  2. Macro VBA to copy and paste cells from one open workbook to another open workbook
    By bloomingcarrot in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-23-2014, 07:55 PM
  3. VBA code to open new workbook and copy and paste special values
    By oddinho2 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-12-2013, 11:24 PM
  4. Open workbook, filter values, copy/paste into Active workbook.
    By niceguy21 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-10-2013, 12:17 PM
  5. Replies: 2
    Last Post: 09-11-2012, 09:42 AM
  6. Simple task: Open a workbook, copy a range, paste into another workbook
    By fbonetti in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-21-2011, 01:12 PM
  7. Macro to open workbook and copy and paste values in to orig workbo
    By Dena X in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-15-2005, 08:20 PM

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.6.0 RC 1