excel中同一工作薄不同工作表的同一位置汇总

2025-10-14 18:41:58

1、首先要知道Excel 或者WPS中有VBA这个功能

excel中同一工作薄不同工作表的同一位置汇总

2、然后复制这个代码,我这里灵活的写的是将表格的最后一行数据汇总到汇总表里

3、Private Sub Worksheet_Activate()

Dim a, b, c, d, e, ar(), br(), sh As Worksheet

d = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row

If d <> 1 Then

    Sheet1.Range(Cells(2, 1), Cells(d, 40)).ClearContents

End If

ar = Sheet1.Range(Cells(1, 1), Cells(Sheets.Count, 40))

a = 2

For Each sh In Sheets                                   '

    If sh.Name <> "汇总" Then

        ar(a, 1) = sh.Name

        c = sh.Cells(Rows.Count, 1).End(xlUp).Row

        For b = 1 To 39

            ar(a, b + 1) = sh.Cells(c, b)

        Next

        a = a + 1

    End If

Next

Sheet1.[a1].Resize(UBound(ar), UBound(ar, 2)) = ar

End Su

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢