以下是从每个工作表的最后一列获取数据并将其显示在工作表“MainSheet”中的代码。由于最后一列已合并单元格,此代码还删除了中间的单元格此代码将数据显示为 MainSheet 中的垂直视图,我想让它水平,即应将每张表最后一列的数据提取到应注意 MainSheet 以及合并的单元格
Sub CopyLastColumns()
    Dim cnt As Integer, sht As Worksheet, mainsht As Worksheet, col As Integer, rw As Integer
    ActiveSheet.Name = "MainSheet"
    Set mainsht = Worksheets("MainSheet")
    cnt = 1
    For Each sht In Worksheets
        If sht.Name <> "MainSheet" Then
            sht.Columns(sht.Range("A1").CurrentRegion.Columns.Count).Copy
            mainsht.Columns(cnt).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
            mainsht.Cells(150, cnt) = sht.Range("A2")
            cnt = cnt + 1
        End If
    Next sht
    With mainsht
        For col = 1 To cnt
            For rw = .Cells(65536, col).End(xlUp).row To 1 Step -1
                If .Cells(rw, col) = "" Then
                    .Cells(rw, col).Delete Shift:=xlUp
                End If
            Next rw
        Next col
    End With
End Sub
提前致谢