20190118_xlVBA多表合并

Posted nextseven

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了20190118_xlVBA多表合并相关的知识,希望对你有一定的参考价值。

Public Sub simple()
    Set wb = ActiveWorkbook
    Set sht = ActiveSheet
    msg = MsgBox("程序准备清除活动工作表内容?按是确认,按否退出!", vbYesNo, "Tips")
    If msg = vbNo Then Exit Sub
    msg = MsgBox("请您确认是否对本文件做好了备份,宏运行之后不可恢复?按是确认,按否退出!", vbYesNo, "Tips")
    If msg = vbNo Then Exit Sub
    sht.Cells.Clear
    head = Application.InputBox("请输入表头行数", "InputBox", , , , , , 1)
    If head = False Then head = 0
    tail = Application.InputBox("请输入表尾行数", "InputBox", , , , , , 1)
    If tail = False Then tail = 0
    shtFilter = Application.InputBox("请输入工作表过滤字符 : ", "InputBox", , , , , , 2)
    If shtFilter = False Then shtFilter = ""
    counter = 0
    For Each onesht In wb.Worksheets
        If onesht.Name Like "*" & shtFilter & "*" Then
            counter = counter + 1
            Debug.Print onesht.Name
            With onesht
                If Application.WorksheetFunction.CountA(.Cells) > 0 Then
                    EndCol = 50 ‘ .Cells.Find("*", .Cells(1, 1), xlValues, xlWhole, xlByColumns, xlPrevious).Column
                    
                    EndRow = .Cells.Find("*", .Cells(1, 1), xlValues, xlWhole, xlByRows, xlPrevious).Row
                    If counter = 1 Then
                        Set scrRng = .Range(.Cells(1, "a"), .Cells(EndRow - tail, EndCol))
                        scrRng.Copy sht.Cells(1, 1)
                    Else
                        Set scrRng = .Range(.Cells(head + 1, 1), .Cells(EndRow - tail, EndCol))
                        With sht
                            nextRow = .Cells.Find("*", .Cells(1, 1), xlValues, xlWhole, xlByRows, xlPrevious).Row + 1
                            scrRng.Copy sht.Cells(nextRow, 1)
                        End With
                    End If
                End If
            End With
        End If
    Next
End Sub

  

以上是关于20190118_xlVBA多表合并的主要内容,如果未能解决你的问题,请参考以下文章

20161212xlVBA文本文件多列合并

20161227xlVBA多文件合并计算

20161212xlVBA工作表数据整理合并单元格

20170622xlVBA多部门分类汇总同类合并单元格

20190321xlVBA_明细信息表汇总成数据表

20190226_xlVba提取查新标题和关键词