如何将公式值粘贴为文本?

我在VBA下使用粘贴数据作为单个单元格B3的值。

Sub pastevalues() Dim ws As Worksheet Set ws = Sheets("data") ws.Range("B3").Copy ws.Range("B3").PasteSpecial Paste:=xlPasteValues Application.CutCopyMode = False End Sub 

我想为列的范围做同样的事情。 我怎样才能做到这一点,而不是为每个细胞编写相同的公式。 我想用这个公式从B3,C3,D3,E3,F3开始,直到它们对应的最后一个单元格。

下面的过程将采用当前范围select中的所有单元格,并将任何公式转换为值。 快速,简单,灵活。

 Sub PasteValues() Dim rngCell As Range For Each rngCell In ActiveWindow.RangeSelection rngCell.Value = rngCell.Value Next rngCell End Sub 

您可以使用这种方法来适应您的需求。 单元格(行,列)而不是范围(“A1”)

 Private Sub SimpleCopyPaste() Dim lastCol As Long Dim rowNum As Long LastCol = Sheets("data").Cells(1, Columns.Count).End(xlToLeft).Column rowNum = 3 'You can get to the row number several different ways. 'Your original question was for B3,C3,D3, so this example just sets Row3 For col = 2 to lastCol Sheets("data").Cells(rowNum, col).Value = Sheets("data").Range("B3").Value next col End Sub