分享

如何快速汇总多工作表数据成总表?

 Jeremy_苍 2020-09-14
Sub WorkSheetsMerge()    Application.ScreenUpdating = False    Cells.ClearContents '清空当前表格数据    Cells.Clear '清空当前表格格式    Range("A3") = "来源工作表名称"    Range("B2") = " " '占位    Tempelete = "WorkSheets Merge Tool"    nTitleRow = Val(InputBox("请输入标题的行数,默认标题行数为1" & vbCrLf & "如无标题行则行数填写 0", Tempelete, 1))    If nTitleRow < 0 Then MsgBox "标题行数不能为负数。", 64, "警告": Exit Sub    For i = 1 To Sheets.Count        If Sheets(i).Name <> ActiveSheet.Name Then            rowused = Cells(Rows.Count, 2).End(xlUp).Row + 1            nShtCount = nShtCount + 1 '汇总工作表的数量            nStartRow = IIf(nTitleRow, nTitleRow, 0) '判断遍历数据源是否应该扣掉标题行            lastrow = rowused            If nShtCount = 1 Then                Sheets(i).UsedRange.Offset(0).Copy Cells(rowused, 2)                rowused = Cells(Rows.Count, 2).End(xlUp).Row                ActiveSheet.Range(Cells(lastrow + 1, 1), Cells(rowused, 1)) = Sheets(i).Name            Else                Sheets(i).UsedRange.Offset(nStartRow).Copy Cells(rowused, 2)                rowused = Cells(Rows.Count, 2).End(xlUp).Row                ActiveSheet.Range(Cells(lastrow, 1), Cells(rowused, 1)) = Sheets(i).Name            End If        End If    Next    Cells.Select    Cells.EntireColumn.AutoFit    Application.ScreenUpdating = True    Range("A3").Select    MsgBox "当前工作簿下的全部工作表已经合并完毕!" & vbCrLf & "一共汇总完成 " & nShtCount & "个工作表!", vbInformation, TempeleteEnd Sub

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多