|
- Sub tt()
- Dim fso, fs, f, i%, wb, pa$, ar, a$, b$, r%
- Set fso = CreateObject("scripting.filesystemobject")
- pa = ThisWorkbook.Path
- Set fs = fso.getfolder(pa).Files
- a = ThisWorkbook.Sheets(1).[m35]
- b = ThisWorkbook.Sheets(1).[m36]
- Set s = ThisWorkbook.Sheets.Add(after:=Sheets(Sheets.Count))
- s.Name = "结果"
- r = 1
- For Each f In fs
- If f.Name Like "*xls" Then
- Set wb = GetObject(f)
- With wb.Sheets(1).[a1].CurrentRegion
- Sheet1.[a1].Resize(1, 9).Copy s.Cells(r, 1).Resize(1, 9)
- r = r + 1
- For i = 1 To .Rows.Count
- If .Cells(i, 1).Value = b Then
- .Cells(i, 1).Resize(1, 9).Copy s.Cells(r, 1).Resize(1, 9)
- r = r + 1
- End If
- Next i
- r = r + 1
-
- For i = 1 To .Rows.Count
- If .Cells(i, 1).Value = a Then
- .Cells(i, 1).Resize(1, 9).Copy s.Cells(r, 1).Resize(1, 9)
- r = r + 1
- End If
- Next i
- r = r + 1
- wb.Close
- End With
- End If
- Next f
- Set fso = Nothing
- Set fs = Nothing
- Set wb = Nothing
- End Sub
复制代码 |
|