Set startRange = ThisWorkbook.Worksheets("Sheet3").Range("a65536").End(xlUp)
Worksheets("Sheet1").Range("B2:B" & lastrowA).Copy startRange1.Offset(1, 2).Value
Worksheets("Sheet2").Range("A2:A" & lastrowA).Copy startRange1.Offset(1, 1)
Application.CutCopyMode = False
我只想复制单元格值而不是其中的公式,因为当我将其复制到其他工作表并保存文件时出现问题。我也试过了value2,但它没有用。请帮助谢谢。
答案 0 :(得分:2)
要仅粘贴值,您需要使用PasteSpecial
- 方法。
将您的代码更改为:
Set startRange = ThisWorkbook.Worksheets("Sheet3").Range("a65536").End(xlUp)
Worksheets("Sheet1").Range("B2:B" & lastrowA).Copy
startRange1.Offset(1, 2).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Worksheets("Sheet2").Range("A2:A" & lastrowA).Copy
startRange1.Offset(1, 1).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
我相信它应该按预期工作。您可能还想粘贴数字格式,在这种情况下,您将xlPasteValues
更改为xlPasteValuesAndNumberFormats
。有关使用PasteSpecial
可以执行的操作的详细信息,建议您查看我上面链接的网站。
答案 1 :(得分:1)
试试这个,更容易理解。
Sub PasteThem()
Dim oRngCopy As Range, oRngPasteTo As Range, lastrowA As Long
lastrowA = 123 ' Whatever you get this from...
' Locate where to start pasting
Set oRngPasteTo = ThisWorkbook.Worksheets("Sheet3").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
' Sets Range 1 to copy
Set oRngCopy = Worksheets("Sheet1").Range("B2:B" & lastrowA)
' Copy the Range
oRngCopy.Copy
oRngPasteTo.PasteSpecial xlPasteValues
' Adjust the Range to start pasting
Set oRngPasteTo = oRngPasteTo.Offset(oRngCopy.Rows + 1, 0)
' Sets Range 2 to copy
Set oRngCopy = Worksheets("Sheet2").Range("A2:A" & lastrowA)
' Copy the Range
oRngCopy.Copy
oRngPasteTo.PasteSpecial xlPasteValues
' Clean Up
Set oRngCopy = Nothing
Set oRngPasteTo = Nothing
End Sub