【问题标题】:Need to add paste special condition a copy.destination for loop需要添加粘贴特殊条件a copy.destination for 循环
【发布时间】:2012-05-22 19:15:47
【问题描述】:

我有一系列数据在书中的每个工作表中处于相同位置,并且将始终处于该位置。运行宏时,应将数据复制并添加到报告表中。我有那部分工作,但我需要使用特殊粘贴:

.PasteSpecial xlPasteValues

因为该范围内有公式。我不确定在此代码中的何处添加粘贴特殊条件,因为我使用的是.Copy, Destination

Option Explicit
Sub CreateTempPSDReport()

    Dim WS As Worksheet, Rept As Worksheet

    Set Rept = Sheets("Temporary PSD Report")

    Application.ScreenUpdating = False

    '--> Loop through each worksheet except the report and
    '--> Copy the set range to the report
    For Each WS In ThisWorkbook.Worksheets
        If Not WS.Name = "Temporary PSD Report" Then
            WS.Range("A42", "I42").Rows.Copy _
            Destination:=Rept.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
        End If
    Next

    Application.ScreenUpdating = True

End Sub

【问题讨论】:

    标签: excel for-loop copy-paste vba


    【解决方案1】:
           I need to use a paste special:
           WS.Range("A42", "I42").Rows.Copy _
           Destination:=Rept.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
    

    在这种情况下,您不要使用上述方法。你用这个

    WS.Range("A42", "I42").Rows.Copy
    
    Rept.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial _
    Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    

    【讨论】:

    • 太棒了!当我被允许时,我会在 7 分钟内接受这个.. :):)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多