Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Copy and paste values with VBA
#1
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.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy data to another worksheet Qomplainerz 0 399 07-27-2023, 11:24 AM
Last Post: Qomplainerz
  Change cell colors based on values with VBA Qomplainerz 0 323 07-27-2023, 08:19 AM
Last Post: Qomplainerz
  Calculate the sum of values in a column with VBA Qomplainerz 0 358 07-27-2023, 08:18 AM
Last Post: Qomplainerz
  Copy data from one workbook to another with VBA Qomplainerz 0 333 07-27-2023, 08:02 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 4 Guest(s)