|
插入表格,修改表名不影响汇总
Sub allsum()
If Sheets.Count = 1 Then Exit Sub
Sheets(Sheets.Count).Select
Cells.ClearContents
For i = 1 To Sheets.Count - 1
last = Sheets(i).UsedRange.Cells(Sheets(i).UsedRange.Rows.Count, 1).Row
Sheets(i).Range("A2:E" & last).Copy
sumlast = Sheets(Sheets.Count).UsedRange.Cells(Sheets(Sheets.Count).UsedRange.Rows.Count, 1).Row
Sheets(Sheets.Count).Range("A" & sumlast).PasteSpecial Paste:=xlPasteValues
Next
Sheets(Sheets.Count).Columns("A:H").Select
ActiveWorkbook.Worksheets(Sheets.Count).Sort.SortFields.Clear
ActiveWorkbook.Worksheets(Sheets.Count).Sort.SortFields.Add2 Key:=Range("A1:A87"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("汇总").Sort
.SetRange Range("A1:E87")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
sumlast = Sheets(Sheets.Count).UsedRange.Cells(Sheets(Sheets.Count).UsedRange.Rows.Count, 1).Row
j = 2
For i = 1 To sumlast
If mc <> Sheets(Sheets.Count).Range("A" & i) Then
mc = Sheets(Sheets.Count).Range("A" & i)
Sheets(Sheets.Count).Range("G" & j) = mc
Sheets(Sheets.Count).Range("H" & j) = Application.SumIf(Sheets(Sheets.Count).Range("A:A"), Sheets(Sheets.Count).Range("G" & j), Sheets(Sheets.Count).Range("E:E"))
j = j + 1
End If
Next
Selection.Columns.AutoFit
Sheets(Sheets.Count).Columns("E:E").NumberFormatLocal = "0.00_ "
Sheets(Sheets.Count).Columns("H:H").NumberFormatLocal = "0.00_ "
End Sub
|
|