07-27-2023, 09:08 AM
Example:
Sub CopyPasteValues()
Dim sourceRange As Range
Dim destinationRange As Range
'Set the source and destination ranges
Set sourceRange = Range("A1:A5")
Set destinationRange = Range("B1:B5")
'Copy and paste values from source to destination
sourceRange.Copy
destinationRange.PasteSpecial xlPasteValues
Application.CutCopyMode = False
End Sub
Explanation:
The code defines a subroutine named CopyPasteValues.
It declares two variables sourceRange and destinationRange, representing the ranges from which to copy values and where to paste them.
The Set statement is used to define the source range (A1:A5) and the destination range (B1:B5).
The Copy method is used to copy the values from the sourceRange to the clipboard.
The PasteSpecial method is used to paste only the values from the clipboard to the destinationRange.
Application.CutCopyMode = False clears the clipboard and ends the copy mode.
Sub CopyPasteValues()
Dim sourceRange As Range
Dim destinationRange As Range
'Set the source and destination ranges
Set sourceRange = Range("A1:A5")
Set destinationRange = Range("B1:B5")
'Copy and paste values from source to destination
sourceRange.Copy
destinationRange.PasteSpecial xlPasteValues
Application.CutCopyMode = False
End Sub
Explanation:
The code defines a subroutine named CopyPasteValues.
It declares two variables sourceRange and destinationRange, representing the ranges from which to copy values and where to paste them.
The Set statement is used to define the source range (A1:A5) and the destination range (B1:B5).
The Copy method is used to copy the values from the sourceRange to the clipboard.
The PasteSpecial method is used to paste only the values from the clipboard to the destinationRange.
Application.CutCopyMode = False clears the clipboard and ends the copy mode.