This Excel VBA tutorial explains how to use Range.PasteSpecial Method to paste special such as paste values.
Excel VBA Range PasteSpecial Method
In Excel worksheet, if you copy a Cell and then Paste Special, you can see a list of options. The most commonly used Paste Special is Paste Values, in order to remove all the formula.
In Excel VBA, Paste Speical is done through Range.PasteSpecial Method.
Syntax of Range.PasteSpecial Method
Range.PasteSpecial(Paste, Operation, SkipBlanks, Transpose)
Name | Required/Optional | Description | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Paste | Optional |
|
||||||||||||||||||||||||||
Operation | Optional |
|
||||||||||||||||||||||||||
SkipBlanks | Optional | True to have blank cells in the range on the Clipboard not be pasted into the destination range. The default value is False. | ||||||||||||||||||||||||||
Transpose | Optional | True to transpose rows and columns when the range is pasted.The default value is False. |
Example 1 – Paste Value
The below VBA copy the whole active worksheet and paste as value.
Public Sub pasteVal() ActiveSheet.Cells.Copy ActiveSheet.Cells.PasteSpecial Paste:=xlPasteValues End Sub
Example 2 – Multiply
Suppose we want to multiply Range A1:C2 by 2.
Public Sub pasteMultiply()
Range("E1").Copy 'Suppose E1 contains value 2
Range("A1:C2").PasteSpecial Operation:=xlPasteSpecialOperationMultiply
End Sub
Result
Copy and Paste in one line
Incidentally, if you just want to copy and paste normally, you can use Copy Method with Destination argument.
The below example copy Range A1:C2 and paste in A10.
Public Sub cpy() Range("A1:C2").Copy Destination:=Range("A10") End Sub