|
- Sub qs()
- Application.ScreenUpdating = False: Application.DisplayAlerts = False
- Dim arr, i, wb As Workbook, xb As Workbook, FileName, brr, rw
- Sheet1.Range("a1").Offset(1).Resize(50000, 20).Clear
- brr = Sheet1.Range("a1").CurrentRegion.Value
- Set wb = ThisWorkbook
- '可多选文件对话框
- FileName = Application.GetOpenFilename(FileFilter:="Excel 工作簿文件 (*.xls*),*.xls*", Title:="请选择文件", MultiSelect:=True)
- If Not IsArray(FileName) Then
- MsgBox "没有选择文件"
- Exit Sub
- End If
- With wb.Sheets(1)
- For Each f In FileName '循环已经选了文件
- rw = .Cells(Rows.Count, 1).End(3).Row + 1
- Set xb = Workbooks.Open(f, 0)
- arr = xb.Sheets(1).Range("a1").CurrentRegion
- For b = 1 To UBound(brr, 2)
- For a = 1 To UBound(arr, 2)
- If brr(1, b) = arr(1, a) Then
- .Cells(rw, b).Resize(UBound(arr), 1) = Application.Index(arr, 0, a)
- Exit For
- End If
- Next a
- Next b
- xb.Close (0)
- .Rows(rw).Delete
- Next f
- End With
- Application.ScreenUpdating = True: Application.DisplayAlerts = True
复制代码 |
|