|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
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 |
|