2012-05-15 40 views
2

我有一系列的數據是在一本書的每個工作表的同一位置,並始終處於那個位置。當宏運行時,數據應該被複制並添加到報表中。我有這部分工作,但我需要使用特殊的粘貼:需要添加特殊粘貼條件的copy.destination for循環

.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 

回答

2
 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 
+0

太棒了!我可以在7分鐘內接受這個.. :) :) –