Results 1 to 5 of 5

Moving data from one workbook to another

Threaded View

Allerdrengen Moving data from one workbook... 07-12-2017, 10:19 AM
CK76 Re: Moving data from one... 07-12-2017, 10:35 AM
Allerdrengen Re: Moving data from one... 07-13-2017, 04:25 AM
JOHN H. DAVIS Re: Moving data from one... 07-12-2017, 10:54 AM
JOHN H. DAVIS Re: Moving data from one... 07-13-2017, 06:15 AM
  1. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Moving data from one workbook to another

    I'd use ADO.

    Sub Demo()
    Dim cn As Object, rst As Object
    Dim strQuery As String
    Dim ws As Worksheet
    
    Set cn = CreateObject("ADODB.Connection")
    With cn
        .Provider = "Microsoft.ACE.OLEDB.12.0"
        .ConnectionString = "Data Source=" & ThisWorkbook.Path & "\WorkbookA.xlsx;" & _
                            "Extended Properties=""Excel 12.0 Xml;HDR=Yes:"""
        .CursorLocation = 3
        .Open
    End With
    
    For Each ws In ThisWorkbook.Worksheets
        strQuery = "SELECT [Value 1], [Value 2], [Value 3] FROM [Sheet1$] WHERE [ID:] = """ & ws.[B1].Value & """"
    
        Set rst = CreateObject("ADODB.Recordset")
        rst.Open strQuery, cn, 1, 3
        
        If rst.RecordCount > 0 Then
            ws.Range("D2").CopyFromRecordset rst
        End If
    Next
    
    rst.Close
    cn.Close
    
    End Sub
    Save both attached to same folder. And while WorkbookA is closed, run code in WorkbookB.
    Attached Files Attached Files
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Moving data between worksheets within the same workbook
    By CountryPenguin in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-26-2015, 12:41 PM
  2. Moving Data from One Workbook to Another Workbook
    By abutler911 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-16-2013, 04:10 PM
  3. Moving data between two workbook with one a variable name
    By Scans in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-10-2012, 07:35 PM
  4. Replies: 4
    Last Post: 09-15-2012, 02:18 PM
  5. Moving data to a closed workbook
    By bouncey in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-29-2010, 10:31 PM
  6. Moving Changing data to new tab in workbook
    By Lime in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-23-2005, 11:40 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