调整模块仅粘贴值,而不是公式

时间:2013-02-28 12:47:05

标签: excel vb.net copy-paste

有人可以帮助我。我运行下面的模块,它工作正常,但它粘贴单元格(公式)的内容而不是值。我知道它是一个特殊的粘贴值,但不知道在哪里调整。此外,我希望从一个跨越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 个答案:

答案 0 :(得分:1)

只需使用pasteSpecial

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

xRng.PasteSpecial(Microsoft.Office.Interop.Excel.XlPasteType.xlPasteFormulas)
相关问题