+ Reply to Thread
Results 1 to 5 of 5

Transfer Data from One Workbook to Another

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-15-2013
    Location
    United States
    MS-Off Ver
    Excel 2016
    Posts
    214

    Transfer Data from One Workbook to Another

    Hello,

    Does anybody know how to transfer data from one workbook that's open to another in a macro form. I included two sample data workbooks I have. Sample will have the macro inside it and will already be open for the other portion of the macro that will be running. I already have code that will open up the Sample2 file. I'm trying to take specific data from Sample and paste it into a summary sheet in Sample2. In Sample i will be cycling through roughly 30 sheets to find this data but I only included one because I just need to know the basics on how to make this work and then I can figure out how to modify it. Any help is greatly appreciated. Thanks again.

    Sample2.xlsx Sample.xlsx

  2. #2
    Forum Contributor
    Join Date
    06-15-2013
    Location
    United States
    MS-Off Ver
    Excel 2016
    Posts
    214

    Re: Transfer Data from One Workbook to Another

    Does anybody have any ideas?

  3. #3
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: Transfer Data from One Workbook to Another

    Hi Trevor,

    I am in the middle of something very similar to your project and facing the same issue.

    I posted yesterday and received some valuable suggestions, take a look a this thread for starters
    http://www.excelforum.com/excel-prog...ame-macro.html

    I am still implementing it but I have seen previously that the guys who responded to my post are, in australian terms "blo*dy good" so I am confident it will work

    Cheers

    Jmac1947

    1. Please consider clicking on the * Add Reputation if you think this post has helped you
    2. Mark your thread as SOLVED when question is resolved

  4. #4
    Forum Contributor
    Join Date
    06-15-2013
    Location
    United States
    MS-Off Ver
    Excel 2016
    Posts
    214

    Re: Transfer Data from One Workbook to Another

    Thanks for the reply. That's somewhat the same as mine. Instead of copying an entire sheet from my second file I'll actually will be pasting information from Sample 1 into Sample 2 and continue going back and fourth between the two workbooks. I have about 30 separate people that represent a sheet in sample 1 that I will need to gather information for and each person I will need to get about 10 different fields of information. Does anybody have any ideas?

  5. #5
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: Transfer Data from One Workbook to Another

    Hi Trevor,

    I do see the differences in need. As you could tell from my thread this is not my strength just yet.

    Here is a block of code that I found on a thread many months ago. The code was posted by someone who had lifted if from some one else and didn't have a clue what it was doing.

    One of the really senior forum members took the trouble to detail exactly what the code was doing (and I apologise to the author as I didn't record who made the comments)

    It is about looping through workbooks so it may be of some guidance

    '
    '   this has some very useful explanations about workbooks
    '
    
    Sub WBLoop()
        Dim MasterWb As Workbook
        Dim tmpWb As Workbook
        Dim i As Long, iCount As Long
        Dim tmpDate As String, tmpStr As String
        
        ' Use the variable MasterWB to refer to the workbook that contains this code
        ' Must use Set because a workbook is an object. An object variable is effectively a pointer to an object,
        ' so MasterWb now will point to the same workbook as ThisWorkbook.
        Set MasterWb = ThisWorkbook
    
        ' For Each is a kind of a loop. It uses the variable tempWb as a workbook to cycle through every
        ' workbook that is currently open. Application.Workbooks is a Collection of all workbooks that are
        ' currently open
        For Each tmpWb In Application.Workbooks
    
            ' We want to ignore the remaining code for this workbook and for Personal.xls, so we check the name
            ' of tempWb and execute the code only if the name is not the name of this workbook and not Personal.xls
            If tmpWb.Name <> MasterWb.Name And _
               tmpWb.Name <> "Personal.xls" Then
    
                ' tmpStr is set to be the value found in cell A3 of the worksheet in the first tab of tmpWB
                tmpStr = tmpWb.Sheets(1).Range("A3").Value
    
                ' If the string is not empty and its length is >5 (redundant) then...
                If tmpStr <> "" And Len(tmpStr) > 5 Then
    
                    ' set tmpDate equal to the substring of tempStr starting with the 6th character and ending at the character counted as the length
                    ' of the string - 5. [It seems to be like there is a flaw in that logic because if the string has 6 characters, you can't go from character 6
                    ' to character 1]. Then strip off any leading and trailing spaces.
                    ' Judging by the name of the variable, perhaps we are expecting this to be  date
                    tmpDate = Trim(Mid(tmpStr, 6, Len(tmpStr) - 5))
    
                    ' If tmpDate is the same as the value in the named range "vDate" in Sheet1 of the active workbook then...
                    If tmpDate = Sheet1.Range("vDate").Value Then
    
                        ' Set iCount to the number of nonblank cells in sheet 2014, range A3:Z3
                        iCount = WorksheetFunction.CountA(MasterWb.Sheets("2014").Range("A3:Z3"))
    
                        ' Copy the contents of Sheet1 A1:A5 of the active workbook to Sheet1 cell B3 of tmpWB in the loop
                        Sheet1.Range("A1:A5").Copy tmpWb.Sheets("Sheet1").Range("B3")
    
                        ' Use shortcut notation, now everything starting with a dot will be interpreted as referring to tmpWb
                        With tmpWb
    
                            ' Force a recalculation on the first sheet of tmpWB
                            .Sheets(1).Calculate
    
                            ' Cause the current workbook to be the active workbook
                            .Activate
    
                             ' Copy to the clipboard from the first sheet of tmpWB from B3 to the last used cell in column B
                            .Sheets(1).Range(Range("B3"), .Sheets(1).Range("B1000000").End(xlUp)).Copy
                        End With
    
                        ' Make this workbook the active workbook
                        MasterWb.Activate
    
                        ' For 1 to iCount (see note above for what iCount is), if the cell in this workbook, sheet 2014, row 3, column i, is equal to the
                        ' value of the named range vDate in Sheet1 of this workbook, then...
                        For i = 1 To iCount
                            If MasterWb.Sheets("2014").Cells(3, i).Value = Sheet1.Range("vDate").Value Then
    
                                ' paste the values from the clipboard into row 4, column i
                                MasterWb.Sheets("2014").Cells(4, i).PasteSpecial xlPasteValues
                            End If
                        Next i
                    End If
                End If
            End If
        Next tmpWb
    End Sub
    '
    jmac

+ 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: 3
    Last Post: 02-21-2014, 09:05 AM
  2. Transfer Data from Open workbook to Close workbook
    By alexnkc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-13-2013, 10:46 PM
  3. [SOLVED] Error 1004 when trying to modify and transfer data from one workbook to a new workbook
    By jecook in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2013, 02:51 AM
  4. Transfer Data from one workbook to worksheets in a closed workbook by criteria
    By jftapel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-21-2012, 05:23 AM
  5. transfer data from open workbook to closed workbook
    By stevesunfold in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 12-23-2008, 08:30 AM

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