代码如下,你可以自己在要合并文件的目录里建立一个新的工作薄,在sheet1上点击鼠标右键选查看代码 然后复制粘贴下面的代码,执行.也可以下载附件放到你要合并文件的目录中,打开这个文件 按ALT+F8 选中"合并孙五" 点击执行.
Sub 合并孙五()
On Error Resume Next
Sheet1.Cells = ""
Dim FileName As String
Dim WK As Workbook
Dim MyEndRow As Long
Dim Rng As Range
FileName = Dir(ThisWorkbook.Path & "\*.xls")
If FileName <> "" Then
Do
If FileName <> ThisWorkbook.Name Then
N = N + 1
Set WK = Workbooks.Open(ThisWorkbook.Path & "\" & FileName)
MyEndRow = Range("A65536").End(xlUp).Row
WK.Sheets("孙五").UsedRange.Copy
Range("A" & MyEndRow + 1).PasteSpecial
WK.Close
End If
FileName = Dir
Loop While FileName <> ""
End If
BT = Range("A2").Value
For Each Rng In Range("A3:A" & UsedRange.Rows.Count)
If Rng.Value = BT Then Rng.EntireRow.Delete
Next
MsgBox "处理完毕!共处理文件" & N & "个."
End Sub