VBA复制合并区域

时间:2018-05-18 11:54:24

标签: vba excel-vba excel

我正在尝试在另一个工作簿中提交一组数据,然后复制整个范围的过滤数据并将其粘贴到ppt中。我设法使过滤器工作,但我正在努力复制合并的数据。

我收到错误

  

运行时eror'1004':应用程序定义或对象定义的错误。

rng.MergeArea.Copy

Function FilterCopyPasteActionLog(Sld As Integer, rng As Range, LeftPos As Integer, TopPos As Integer, WidthPos As Integer, HeightPos As Integer, DataTyp As Integer, wB As String, sH As String) As Object
        If PPT Is Nothing Then Exit Function
        If PPT_pres Is Nothing Then Exit Function

        Dim mySlide As Object
        Dim myShape As Object

        Workbooks(wB).Worksheets(sH).Activate

        'Find the LastRow
        Dim LastLine As Long
        LastLine = Columns(1).Find("*", , , , xlByColumns, xlPrevious).Row

        'Add filter
        Range("A:H").AutoFilter Field:=8, Criteria1:="Open"

        'Copy the filtered data.
        Set rng = Range("A1").CurrentRegion

        rng.MergeArea.Copy 'ERROR HERE

        Set mySlide = PPT_pres.Slides(Sld)

        PasteRngIntoSlide mySlide, DataTyp

        PositionChart LeftPos, TopPos, WidthPos, HeightPos

        'Clear Clipboard
        Application.CutCopyMode = False

任何帮助,或向正确的方向推进都将非常感激。

由于

1 个答案:

答案 0 :(得分:1)

CurrentRegionMergeArea是两个不同的属性,无法组合在一起。你几乎是在写这个:

Public Sub TestMe()    
    Range("A1").CurrentRegion.MergeArea.Copy    
End Sub

始终返回1004错误。要查看MergedArea中的CurrentRegionCurrentRegion周围的循环是可行的:

Public Sub TestMe()
    Dim myCell As Range
    For Each myCell In Range("A1").CurrentRegion
        If Not myCell.MergeArea.Cells.Count = 1 Then
            myCell.Copy
        End If
    Next myCell
End Sub