|
- Sub Main()
- On Error Resume Next
- Dim sht As Worksheet
- Dim pend As Worksheet
- Application.DisplayAlerts = 0
- Sheets("汇总").Delete
- Set pend = Sheets("汇总")
- Application.ScreenUpdating = 0
- If Err.Number <> 0 Then
- Set pend = Sheets.Add
- pend.Name = "汇总"
- pend.Move Sheets(1)
- End If
- On Error GoTo 0
- Dim r As Range, used As Range, cur As Range, f As Range
- Dim n%, j%, total As Range
- n = Sheets.Count
- Set r = pend.Range("a3")
- For i% = 1 To n
- If Sheets(i).Name <> pend.Name Then
- If j > 6 Then Exit For
- Set sht = Sheets(i)
- Set used = sht.UsedRange
- Set f = used.Find("*", SearchDirection:=xlPrevious)
- Set cur = sht.Range(Cells(3, 1), _
- Cells(f.Row - 1, f.Column))
- Set total = sht.Range(Cells(f.Row, 1), Cells(f.Row, f.Column))
- If pend.UsedRange.Count = 1 Then
- cur.Copy r
- Else
- cur.Copy Cells(pend.UsedRange.Find("*", SearchDirection:=xlPrevious).Row, 1)
- End If
- End If
- j = j + 1
- Next
- Set r = Sheets(2).Range("1:2")
- r.Copy pend.Range("a1")
- Set used = pend.UsedRange
- Set used = pend.Range(used(2), used.Resize(used.Rows.Count))
- used.EntireColumn.AutoFit
- Set used = pend.Range(Range("a3"), Cells(used.Rows.Count, used.Columns.Count))
- used.Borders.LineStyle = 1
- If ActiveSheet.Name = pend.Name Then [a1].Select
- Set used = pend.UsedRange
- Set f = pend.Range(Cells(used.Rows.Count, 1), Cells(used.Rows.Count, used.Columns.Count))
- total.Copy f
- Application.ScreenUpdating = 1
- '学习交流群: 223198032
- End Sub
复制代码
最后的公式统计自己看着处理吧 |
|