|
代码供参考。。。- Sub ykcbf() '//2024.2.23
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set sh = ThisWorkbook.Sheets("汇总")
- sh.UsedRange.ClearContents
- p = ThisWorkbook.Path & ""
- f = Dir(p & "*.xls*")
- m = 0
- On Error Resume Next
- Do While f <> ""
- If InStr(f, ThisWorkbook.Name) = 0 Then
- Set wb = Workbooks.Open(p & f, 0)
- Set sht = wb.Sheets("人力成本")
- arr = sht.UsedRange
- m = m + 1
- If m = 1 Then
- sht.UsedRange.Copy sh.[a1]
- sh.[a1].Resize(UBound(arr), UBound(arr, 2)) = arr
- Else
- r = sh.UsedRange.Find("*", , -4163, , 1, 2).Row + 1
- sht.UsedRange.Copy sh.Cells(r, 1)
- sh.Cells(r, 1).Resize(UBound(arr), UBound(arr, 2)) = arr
- End If
- wb.Close False
- End If
- f = Dir
- Loop
- sh.Cells.Replace What:="#REF!", Replacement:="0", LookAt:=xlPart, _
- SearchOrder:=xlByRows, FormulaVersion:=xlReplaceFormula2
- sh.Range("b5").Select
- Application.ScreenUpdating = True
- MsgBox "合并完毕!"
- End Sub
复制代码
|
|