Copy and paste values with VBA - Printable Version +- QP School (https://qomplainerzschool.lima-city.de) +-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3) +--- Forum: Excel VBA Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=48) +--- Thread: Copy and paste values with VBA (/showthread.php?tid=5250) |
Copy and paste values with VBA - Qomplainerz - 07-27-2023 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. |