|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
二楼代码可以提取各个分文件内容,但是各个分文件有很多不可见字符,增加排序就可以了
Sub sss()
Set fso = CreateObject("scripting.filesystemobject")
Set sh = Sheets(1)
Application.ScreenUpdating = False
sh.UsedRange.Offset(1).Clear
For Each f In fso.getfolder(ThisWorkbook.Path).Files
If InStr(f.Name, "csv") > 0 Then
With Workbooks.Open(f)
.Sheets(1).UsedRange.Offset(4).Copy sh.Cells(sh.UsedRange.Rows.Count, 1).Offset(1)
.Close False
End With
End If
Next f
r = Cells(Rows.Count, 1).End(3).Row
Cells.Select
ActiveWorkbook.Worksheets("数据表").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("数据表").Sort.SortFields.Add Key:=Range("A2:A" & r), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("数据表").Sort
.SetRange Range("A1:N" & r)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Application.ScreenUpdating = True
End Sub
|
|