我有多张数据表,其中包含基于particualr列的数据组小计。现在我需要一个vba代码,它将从x张表中取出小计,并将总计复制到一个摘要表中。正如您在下面看到的,代码需要为“SheetName1”的小计插入一行,并填写“SheetName1”的Column3值(A,B和C)的小计,并为其余的工作表填写:
答案 0 :(得分:0)
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