在VBA中只粘贴值问题

我试图只粘贴到目标单元格的值,而不是公式,并没有取得任何成功后,大量的谷歌search。 这是我第一次真正进入VBA,因此我不确定下一步该怎么做。 我目前的代码是:

Function freeCell(r As Range) As Range ' returns first free cell below r Dim lc As Range, Tracking As Worksheet ' last used cell on sheet Set lc = r.Offset(40, 6).End(xlUp).Offset(1, 0) Set freeCell = lc End Function Sub doIt() Dim tCell As Range, sh As Worksheet Sheets("Bundler").Range("G20").Copy Set sh = Sheets(Range("G73").Value) Set tCell = freeCell(sh.Range("A3")) If tCell.Row < 19 Then Set tCell = tCell.Offset(19 - tCell.Row) sh.Paste tCell End Sub 

sh.Paste tCell粘贴到正确的单元格中,但是如何将其转换为仅值? 我知道.PasteSpecial xlPasteValues需要使用,但我不知道如何格式化。

 Sub doIt() Dim tCell As Range, sh As Worksheet Sheets("Bundler").Range("G20").Copy Set sh = Sheets(Range("G73").Value) Set tCell = freeCell(sh.Range("A3")) If tCell.Row < 19 Then Set tCell = tCell.Offset(19 - tCell.Row) tCell.PasteSpecial Paste:=xlPasteValues End Sub 

你可以做到这一点没有复制和粘贴:

 Sub doIt() Dim tCell As Range, sh As Worksheet Set sh = Sheets(Range("G73").Value) Set tCell = freeCell(sh.Range("A3")) If tCell.Row < 19 Then Set tCell = tCell.Offset(19 - tCell.Row) tCell.Formula = Sheets("Bundler").Range("G20").Text End Sub 

如果你想把它作为一个值,将.text改为.value