[英]VBA Add Summary sheet for multiple excel sheets and add the subtotals
我有多張數據表,其中包括基於特定列的數據組小計。 現在,我需要一個vba代碼,該代碼將從x個工作表中獲取小計並將總計復制到單個摘要工作表中。 正如您在下面看到的那樣,代碼需要為“ SheetName1”的小計插入一行,並為“ SheetName1”的Column3值(A,B和C)填寫小計,其余工作表也是如此:
Sub tester()
Dim sht As Worksheet, rw As Range, c As Range, i As Long
Set rw = Sheets("Summary").Cells(Rows.Count, 1).End(xlUp) _
.Offset(1, 0).EntireRow
For Each sht In ActiveWorkbook.Worksheets
If sht.Name <> "Summary" Then
i = 2
rw.Cells(1).Value = sht.Name
Set c = sht.Range("C1")
Do While c.Value <> ""
If c.Value = "Total" Then
rw.Cells(i).Value = c.Offset(0, 1).Value
i = i + 1
End If
Set c = c.Offset(1, 0)
Loop
Set rw = rw.Offset(1, 0)
End If
Next sht
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.