|
Sub zldccmx()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim WK As Workbook, CSV As Workbook, MyPath$, MyName$
MyPath = ThisWorkbook.Path & "\csv\"
MyName = Dir(MyPath & "*.csv")
If MyName <> "" Then Set WK = ThisWorkbook Else Exit Sub
For Each sh In WK.Worksheets
If sh.Name <> "Sheet1" Then sh.Delete
Next
Do While MyName <> "" ' 开始循环。
Set CSV = Workbooks.Open(MyPath & MyName): WK.Sheets.Add
WK.ActiveSheet.Name = Split(MyName, ".")(0)
With CSV.ActiveSheet
ro = .UsedRange.Rows.Count
co = .UsedRange.Columns.Count
.Cells(1, co + 1).Resize(ro, 1) = "=if(RC[-" & co & "]=""b"",0,1/0)"
.Columns(co + 1).SpecialCells(xlCellTypeFormulas, xlErrors).EntireRow.Delete
.Columns(co + 1) = ""
.UsedRange.Copy WK.ActiveSheet.[A1]
CSV.Close False
End With
MyName = Dir
Loop
WK.Save 'As MyPath & "aaa.xls"
MsgBox MyPath & "下所有的CSV文件 均已经汇总到工作簿" & WK.Name & "中!" & vbLf & vbLf & "汇总完成,现在退出!"
Application.EnableEvents = True
End Sub |
|