2013-02-28 91 views
1

有人可以幫助我。我運行下面的模塊,它工作正常,但它粘貼單元格(公式)的內容而不是值。我知道這是一個特殊的粘貼值,但不確定在哪裏調整。此外,我想在複製跨越A:K的變量表中的行,然後粘貼到標識表中。對不起,如果不清楚,不知道爲什麼代碼顯示在下面。從子開始:調整模塊只粘貼值,不是公式

Sub armine_profitTEST() 
    Dim r As Long, endRow As Long, pasteRowIndex As Long 

    endRow = 500 ' of course it's best to retrieve the last used row number via a function 
    pasteRowIndex = 5 

    For r = 1 To endRow 'Loop through sheet1 and search for your criteria 

     If Cells(r, Columns("F").Column).Value = "Armine" Then 'Found 
      'Copy the current row 
      Rows(r).Select 
      Selection.Copy 

      'Switch to the sheet where you want to paste it & paste 
      Sheets("Armine").Select 
      Rows(pasteRowIndex).Select 
      ActiveSheet.Paste 

      'Next time you find a match, it will be pasted in a new row 
      pasteRowIndex = pasteRowIndex + 1 

      'Switch back to your table & continue to search for your criteria 
      Sheets("Summary").Select 
     End If 
    Next r 
End Sub 

回答

1

只需使用pasteSpecial

Dim xRng As Microsoft.Office.Interop.Excel.Range 

xRng.PasteSpecial(Microsoft.Office.Interop.Excel.XlPasteType.xlPasteFormulas) 
+0

遺憾的是無知的,但在將上述代碼做我把它? – user2119567 2013-02-28 14:09:15

+0

@ user2119567這是一個例子。你必須粘貼你想要的數據,在你的情況下,我認爲它應該是'選擇'。而且你必須粘貼你想要的地方和地點,當然O.o – SysDragon 2013-02-28 15:02:36