![](/img/trans.png)
[英]Copying a range of cells and paste only values in the same range in another sheet
[英]Copy (only value and not formula) range of cells to another sheet in same file
我使用以下代碼。 此代碼將單元格公式復制到另一個工作表中。 有誰知道如何修改它只是復制單元格值而不是公式?
sub copyRangeOver()
Dim i As Integer
i = 631
Dim copyRange As Range
Set copyRange = ThisWorkbook.Worksheets("Coupling xyz data").Range("J" & 1 & ":V" & i)
Dim countD As Integer
countD = 1
copyRange.Copy Destination:=Cells(countD, 1)
Dim j As Integer
j = 466
Set copyRange = ThisWorkbook.Worksheets("Spring xyz data").Range("J" & 1 & ":V" & j)
copyRange.Copy Destination:=Cells(i + 1, 1)
End Sub
您可以執行直接值傳輸,這比復制和粘貼特殊值,值更快,並且不涉及剪貼板。
Sub copyRangeOver()
Dim i As Long, j As Long, countD As Long
Dim copyRange As Range
i = 631
countD = 1
With ThisWorkbook.Worksheets("Coupling xyz data")
Set copyRange = .Range("J" & 1 & ":V" & i)
Cells(countD, 1).Resize(copyRange.Rows.Count, copyRange.Columns.Count) = _
copyRange.Value
End With
j = 466
With ThisWorkbook.Worksheets("Spring xyz data")
Set copyRange = .Range("J" & 1 & ":V" & j)
Cells(i + 1, 1).Resize(copyRange.Rows.Count, copyRange.Columns.Count) = _
copyRange.Value
End With
End Sub
這復制了你之前的努力,盡管在我看來,值的目的地存在一些模糊性。 對於要接收值的行,您在第二行中使用i而在第一行中使用CountD ,但它們之間似乎沒有關系。
你需要pastespecial:
copyRange.Copy
Cells(countD, 1).PasteSpecial Paste:=xlPasteValues
這通常是如何完成的。
copyRange.Copy
Cells(i + 1, 1).PasteSpecial xlPasteValues
application.cutcopymode=0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.