Yes. or change this to suit
Code:
Path = ThisBk.Path & "\"
Minor revisions
Code:
Option Explicit
Option Compare Text
Sub test()
Dim Rng
Dim sht As Worksheet
Dim wbk As Workbook
Dim Filename As String
Dim Path As String
Dim ThisBk As Workbook
Dim Tgt As Range
Dim Arr, a
Dim c As Range
Application.ScreenUpdating = False
Application.EnableEvents = False
Arr = Array("ItemID", "XItemID")
Set ThisBk = ActiveWorkbook
Path = ThisBk.Path & "\"
Filename = Dir(Path & "*.xls*")
Do While Len(Filename) > 0
If Filename <> ThisWorkbook.Name Then
Set wbk = Workbooks.Open(Path & Filename, UpdateLinks:=False)
For Each sht In wbk.Worksheets
For Each a In Arr
Set c = sht.Rows(1).Find(a)
If Not c Is Nothing Then
Set Tgt = ThisBk.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp)(2)
On Error Resume Next
Intersect(c.EntireColumn, sht.UsedRange).Copy Tgt
On Error GoTo 0
End If
Next a
Next sht
wbk.Close True
End If
Filename = Dir
Loop
On Error Resume Next ThisBk.Sheets("Sheet1").Columns(1).SpecialCells(xlCellTypeBlanks).Delete
ThisBk.Sheets("Sheet1").Columns(1).SpecialCells(xlCellTypeConstants, xlErrors).Delete
On Error GoTo 0
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub