+ Reply to Thread
Results 1 to 8 of 8

Copy+Paste into other workbook

Hybrid View

  1. #1
    Forum Contributor aaaaa34's Avatar
    Join Date
    12-25-2013
    Location
    Istanbul
    MS-Off Ver
    Office365
    Posts
    388

    Copy+Paste into other workbook

    Hello my friends,
    I need to copy some cells to other opened workbooks at that moment.

    Macro1
    Source cell: AL2:AS2 (8 cells) + AL6:AM6 (2 Cells)
    Target workbook: Second.xlsx Target sheet: Compare Target cell: L10:U10 (all these 10cells will pasted horizontally together)
    I will run macro continously. So macro should check last filled cells in L column. When I run macro first time, paste will be done into L10:U10. Second time when I run it, cells should be pasted into L11:U11
    Macro2
    Source cell: Y2:AH2 (10 cells)
    Target workbook: Third.xlsx Target sheet: Ready Target cell: B2:K2 (10cells)
    Each time when I run it, macro firstly should clear contents in target cells (B2:K2), then i should paste them into target cells.

    Pls have a check files I attached and you will see how macro should do easily with desired result.
    Source file: First.xlsx

    Note: Related cells include formula results, so macros should make paste operation as "Special Paste as values".
    Attached Files Attached Files

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copy+Paste into other workbook

    Hello aaaaa34,

    If all three xlsx workbooks are open then the macros will be a fourth xlsm workbook?

    How will these macros be triggered?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor aaaaa34's Avatar
    Join Date
    12-25-2013
    Location
    Istanbul
    MS-Off Ver
    Office365
    Posts
    388

    Re: Copy+Paste into other workbook

    Related cells are in First.xlsx
    So, First.xlsx can be saved as First.xlsm and two macros can be attached to it.
    and we can open workbooks: Second.xlsx and Third.xlsx and run the macros.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copy+Paste into other workbook

    Hello aaaaa34,

    Okay, that is easily done. How will the macros be run: Manually or triggered by some event?

  5. #5
    Forum Contributor aaaaa34's Avatar
    Join Date
    12-25-2013
    Location
    Istanbul
    MS-Off Ver
    Office365
    Posts
    388

    Re: Copy+Paste into other workbook

    Manually I'd prefer.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copy+Paste into other workbook

    Hello aaaaa34,

    Here are the macros I have added to the workbook "First ver 1.xlsm". There is a second worksheet "Sheet1" that has 2 buttons. One button for each macro.

    Sub Macro1()
    
        Dim c       As Long
        Dim Cell    As Range
        Dim DstWkb  As Workbook
        Dim DstWks  As Worksheet
        Dim LastRow As Long
        Dim r       As Long
        Dim SrcWkb  As Workbook
        Dim SrcWks  As Worksheet
        Dim WkbName As String
        
            WkbName = "Second.xlsx"
            
            Set SrcWkb = ThisWorkbook
            Set SrcWks = SrcWkb.Worksheets("Result")
            
            On Error Resume Next
                Set DstWkb = Workbooks(WkbName)
                If Err = 9 Then
                    MsgBox "The workbook '" & WkbName & "' is Not Open.", vbCritical
                    Exit Sub
                End If
                
                Set DstWks = DstWkb.Worksheets("Compare")
                
                ReDim Data(1 To 1, 1 To 10)
                
                For Each Cell In SrcWks.Range("AL2:AS2")
                    c = c + 1
                    Data(1, c) = Cell.Value
                Next Cell
                
                For Each Cell In SrcWks.Range("AL6:AM6")
                    c = c + 1
                    Data(1, c) = Cell.Value
                Next Cell
                
                r = 10
                LastRow = DstWks.Cells(Rows.Count, "L").End(xlUp).Row
                If LastRow < r Then LastRow = r Else LastRow = LastRow + 1
                
                DstWks.Cells(LastRow, "L").Resize(1, c).Value = Data()
            On Error GoTo 0
            
    End Sub
    
    Sub Macro2()
    
        Dim DstWkb  As Workbook
        Dim DstWks  As Worksheet
        Dim DstRng  As Range
        Dim SrcRng  As Range
        Dim SrcWkb  As Workbook
        Dim SrcWks  As Worksheet
        Dim WkbName As String
        
            WkbName = "Third.xlsx"
            
            Set SrcWkb = ThisWorkbook
            Set SrcWks = SrcWkb.Worksheets("Result")
            Set SrcRng = SrcWks.Range("Y2:AH2")
            On Error Resume Next
                Set DstWkb = Workbooks(WkbName)
                If Err = 9 Then
                    MsgBox "The workbook '" & WkbName & "' is Not Open.", vbCritical
                    Exit Sub
                End If
                    
                Set DstWks = DstWkb.Worksheets("Ready")
                Set DstRng = DstWks.Range("B2:K2")
                
                DstRng.Value = Empty
                DstRng.Value = SrcRng.Value
            On Error GoTo 0
                    
    End Sub
    Attached Files Attached Files

  7. #7
    Forum Contributor aaaaa34's Avatar
    Join Date
    12-25-2013
    Location
    Istanbul
    MS-Off Ver
    Office365
    Posts
    388

    Re: Copy+Paste into other workbook

    Super
    Both two macros work perfectly.

    Only I'd like to ask one point for Macro1
    I asked to paste AL2:AS2 (8 cells) + AL6:AM6 (2 Cells) into L10:U10 (10 cells together)
    If I would ask to paste only AL2:AS2 (8 cells) into L10:S10 (8 cells) , how would you edit the code, sir?

  8. #8
    Forum Contributor aaaaa34's Avatar
    Join Date
    12-25-2013
    Location
    Istanbul
    MS-Off Ver
    Office365
    Posts
    388

    Re: Copy+Paste into other workbook

    oke sorry
    I discovered by myself.
    I only omit this part.
    Thanks a lor Ross.
                For Each Cell In SrcWks.Range("AL6:AM6")
                    c = c + 1
                    Data(1, c) = Cell.Value
                Next Cell

+ 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] VBA Macro pull a certain cell in closed workbook and copy/paste into current workbook
    By Hoover5896 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-08-2017, 01:36 AM
  2. [SOLVED] VBA - Excel code to copy and paste from several Sharepoint workbook files to one workbook
    By TraceyPatterson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-27-2015, 06:45 AM
  3. [SOLVED] Macro to find data in source workbook and copy paste to target workbook
    By D.Lovell in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-23-2014, 06:21 AM
  4. Replies: 6
    Last Post: 03-26-2014, 11:40 PM
  5. 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
  6. Replies: 2
    Last Post: 09-11-2012, 09:42 AM
  7. Copy and paste non consecutive cells and paste consecutively in another workbook
    By macquhele in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-12-2011, 02:36 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