|
- Sub qs()
- Dim wb As Workbook, xb As Workbook, p As String, arr, brr, sht As Worksheet, dic, crr, drr
- Set dic = CreateObject("scripting.dictionary")
- Dim FileName
- Set wb = ThisWorkbook
- '可多选文件对话框
- FileName = Application.GetOpenFilename(FileFilter:="Excel 工作簿文件 (*.xls*),*.xls*", Title:="请选择文件", MultiSelect:=True)
- If Not IsArray(FileName) Then
- MsgBox "没有选择文件"
- Exit Sub
- End If
- For Each f In FileName '循环已经选了文件
- Set xb = Workbooks.Open(f, 0)
- For Each sht In xb.Worksheets
- dic.RemoveAll
- arr = xb.Sheets(sht.Name).Range("c2").Resize(1, 7).Value
- brr = xb.Sheets(sht.Name).Range("c23").Resize(1, 7).Value
- For i = 1 To UBound(brr, 2)
- If Not dic.exists(brr(1, i)) Then
- dic(arr(1, i)) = brr(1, i)
- End If
- Next
- crr = wb.Sheets(sht.Name).Range("c2").Resize(1, 7).Value
- ReDim drr(1 To 1, 1 To UBound(crr, 2))
- For i = 1 To UBound(crr, 2)
- drr(1, i) = dic(crr(1, i))
- Next
- r = wb.Sheets(sht.Name).Cells(Rows.Count, 1).End(xlUp).Row + 1
- wb.Sheets(sht.Name).Range("c" & r).Resize(1, 7) = drr
- wb.Sheets(sht.Name).Range("a" & r).Resize(1, 2).Merge
- wb.Sheets(sht.Name).Range("a" & r) = "姓名"
- Next
- xb.Close (0)
- Next f
- Set wb = Nothing: Set xb = Nothing
- Set sht = Nothing: Set dic = Nothing
- MsgBox "完成!"
- End Sub
复制代码 |
|