复制整行(值不是公式)VBA

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9006541/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 12:28:39  来源:igfitidea点击:

Copy Entire Row (Values not formulas) VBA

excelvba

提问by Jeff_Hd

I need to copy rows between multiple worksheets and while I managed to do that it only copies the formulas and not the values. I haven't used VBA for years and I just can't think of how to do it.

我需要在多个工作表之间复制行,虽然我设法做到了,但它只复制了公式而不是值。我已经多年没有使用 VBA,我只是想不出如何去做。

My existing code is:

我现有的代码是:

Workbooks.Open filename:=NewFN
    filename = Mid(NewFN, InStrRev(NewFN, "\") + 1)


        For i = 1 To 14
            Workbooks(filename).Sheets("sheet1").Rows(i).Copy ThisWorkbook.Sheets("BD Raw Data").Rows(insertRow)

            insertRow = insertRow + 1
        Next i

        Workbooks(filename).Close SaveChanges:=False

采纳答案by Steve Robillard

The choice between values and formulas is made in the paste half of the process. Have a look at the PasteSpecial method specifically the xlPasteValues argument.

值和公式之间的选择是在过程的粘贴一半中进行的。看看 PasteSpecial 方法,特别是 xlPasteValues 参数。

http://msdn.microsoft.com/en-us/library/aa195818(v=office.11).aspx

http://msdn.microsoft.com/en-us/library/aa195818(v=office.11​​).aspx

回答by Conrad Frix

You need to use the PasteSpecialmethod using the XlPasteType.xlPasteValuesenumeration instead of Copy Destination

您需要使用PasteSpecial使用XlPasteType.xlPasteValues枚举的方法 而不是Copy Destination

e.g.

例如

Workbooks(filename).Sheets("sheet1").Rows(i).Copy 
ThisWorkbook.Sheets("BD Raw Data").Rows(insertRow).PasteSpecial Operation:=xlPasteValues

回答by Bruno Leite

Try it

尝试一下

 Sub CopyFormulas()
'http://officevb.com

Dim sht1 As Worksheet, sht2 As Worksheet

Set sht1 = Sheets("Sheet1")
Set sht2 = Sheets("sheet2")

'copy columns C from sht1 formulas to sht2

sht1.Range("C:C").Copy
sht2.Range("C:C").PasteSpecial xlPasteFormulas

Application.CutCopyMode = False

End Sub

This sub copy all formulas in column C from sht1 to column C in sht2

此子将 C 列中的所有公式从 sht1 复制到 sht2 中的 C 列

[]′s

[]的