Copy Entire Row (Values not formulas) VBA

2019-08-04 19:35发布

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.

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

标签: excel vba
3条回答
走好不送
2楼-- · 2019-08-04 20:07

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

[]´s

查看更多
对你真心纯属浪费
3楼-- · 2019-08-04 20:10

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.

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

查看更多
Luminary・发光体
4楼-- · 2019-08-04 20:12

You need to use the PasteSpecial method using the XlPasteType.xlPasteValues enumeration instead of Copy Destination

e.g.

Workbooks(filename).Sheets("sheet1").Rows(i).Copy 
ThisWorkbook.Sheets("BD Raw Data").Rows(insertRow).PasteSpecial Operation:=xlPasteValues
查看更多
登录 后发表回答