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.
Bookmarks