|
需求写的很详细,类似的要求往贴也很多,我把前天写的类似代码发给你参考
Sub 汇总()
Application.ScreenUpdating = False
lj = ThisWorkbook.Path & ""
With Sheets("汇总表")
.Rows("6:200000").Clear
f = Dir(lj & "*.xls*")
Do While f <> ""
If f <> ThisWorkbook.Name Then
Set wb = Workbooks.Open(lj & f, 0)
Set sht = wb.Worksheets(1)
r = sht.Cells(Rows.Count, 2).End(xlUp).Row
If r >= 5 Then
rs = .Cells(Rows.Count, 2).End(xlUp).Row + 1
If rs < 6 Then rs = 6
sht.Rows("6:" & r).Copy .Cells(rs, 1)
End If
wb.Close False
End If
f = Dir
Loop
End With
分类排序
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
Sub 分类排序()
Sheets("汇总表").Rows.Copy Sheets("按行业汇总").[a1]
With Sheets("按行业汇总")
r = .Cells(Rows.Count, 2).End(xlUp).Row
.Rows("6:" & r).Sort [D5], Header:=xlNo
End With
Sheets("汇总表").Rows.Copy Sheets("按产值汇总").[a1]
With Sheets("按产值汇总")
r = .Cells(Rows.Count, 2).End(xlUp).Row
.Rows("6:" & r).Sort [e5], Header:=xlNo
End With
Sheets("汇总表").Rows.Copy Sheets("按增长率").[a1]
With Sheets("按增长率")
r = .Cells(Rows.Count, 2).End(xlUp).Row
.Rows("6:" & r).Sort [g5], Header:=xlNo
End With
End Sub
|
|