|
请各位大神帮帮忙,我需要合并同一个文件夹下的多个表格,要以C列“名称”为提取条件,C列有数据的都需要提取到同一个表格中,下面是附件,希望大神们能帮帮忙!谢谢了!
本帖最后由 冥王 于 2015-10-1 15:15 编辑
- Sub shtHeBing()
- Dim strPath$, strFile$, i%, wb As Workbook
- strPath = ThisWorkbook.Path & ""
- strFile = Dir(strPath & "*.xls")
- Application.ScreenUpdating = False
- With ThisWorkbook.Sheets(1)
- .Cells.Clear
- Do While strFile <> ""
- If strFile = ThisWorkbook.Name Then GoTo 100
- i = i + 1
- Set wb = Workbooks.Open(strPath & strFile)
- If i = 1 Then
- wb.Sheets(1).UsedRange.Copy .Range("A1")
- Else
- wb.Sheets(1).UsedRange.Offset(1, 0).Copy .Cells(Rows.Count, "C").End(xlUp).Offset(1, -2)
- End If
- wb.Close False
- 100:
- strFile = Dir
- Loop
- .Columns("A:F").AutoFit
- .UsedRange.EntireRow.AutoFit
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码
|
|