Sub layxoadulieu()
Dim arr, i As Long, lr As Long, kq, dic As Object, mang, T, dk As String, chon As Boolean, link, wb As Workbook, lc As Long
Dim j As Long, b As Long
Set dic = CreateObject("scripting.dictionary")
ReDim kq(1 To 10000, 1 To 1000)
mang = Application.InputBox("chon du lieu can loc", , Type:=8)
For Each T In mang
dic.Item(T) = T
Next
If MsgBox("Ban chon giu lai hay xoa di", vbYesNo) = vbYes Then
chon = True
End If
Set link = Application.FileDialog(msoFileDialogFilePicker)
link.Show
link.AllowMultiSelect = True
For Each T In link.SelectedItems
Set wb = Workbooks.Open(T)
lc = wb.Sheets(1).Cells(1, Columns.Count).End(xlToLeft).Column
lr = wb.Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
arr = wb.Sheets(1).Range("A1").Resize(lr, lc).Value
For j = 1 To UBound(arr, 2)
dk = arr(1, j)
If dic.exists(dk) = chon Then
b = b + 1
For i = 1 To UBound(arr)
kq(i, b) = arr(i, j)
Next i
End If
Next j
wb.Close False
Next
Set wb = Workbooks.Add
wb.Sheets(1).Range("A1").Resize(10000, b).Value = kq
End Sub