Automating Copying and Pasting VALUES in Excel via Visual Basic

Abstract: Resolve Excel VBA macros that incorrectly copy formulas and formatting by using PasteSpecial xlPasteValues to transfer only calculated results.

Created: 2026-10-22 by

To automate copying and pasting values in Excel via VBA, you must explicitly specify the xlPasteValues paste type to discard formulas and formatting. This process involves selecting the source range, copying it to the clipboard, and then applying the specific paste operation to the destination cell or range, ensuring only the calculated results are transferred.

The Core Mechanism of Value-Only Pasting

When working with Microsoft Excel through Visual Basic for Applications (VBA), the default behavior of the Copy method is to transfer everything: data, formulas, number formats, and conditional formatting rules. However, in many automation scenarios, such as data aggregation or report generation, you strictly need the resulting numbers or text without the underlying logic that generated them. This is where the distinction between a standard paste and a value-only paste becomes critical. The fundamental command that achieves this is the PasteSpecial method applied to a Range object. Unlike the user interface, which offers a dialog box with multiple options, VBA requires you to pass an argument that defines the paste type. The constant xlPasteValues tells Excel to ignore all other attributes and write only the raw content into the target cells. This approach is significantly faster than iterating through cells one by one because it leverages Excel's internal memory management rather than processing each cell individually. To implement this, you typically chain the actions together. You first define your source range, execute the copy command, identify the destination, and finally invoke PasteSpecial. It is important to note that if you do not clear the clipboard after the operation, Excel retains the "marching ants" border around the copied area until you manually cancel it or run another macro. Therefore, good practice dictates clearing the clipboard at the end of your subroutine.

Standard Implementation Using Copy and PasteSpecial

The most common and readable way to handle this task is using the Copy and PasteSpecial methods. This method is intuitive because it mirrors the manual keyboard shortcuts most users are familiar with. Below is a standard implementation pattern that you can adapt to your specific workbook structure.
Sub CopyValuesOnly()
    Dim src As Range
    Dim dest As Range
    
    ' Define the source range containing formulas
    Set src = ThisWorkbook.Sheets("Sheet1").Range("A1:A10")
    
    ' Define the destination range
    Set dest = ThisWorkbook.Sheets("Sheet1").Range("B1")
    
    ' Copy the source range
    src.Copy
    
    ' Paste only the values to the destination
    dest.PasteSpecial Paste:=xlPasteValues
    
    ' Clear the clipboard to remove marching ants
    Application.CutCopyMode = False
End Sub
In this code snippet, Set src assigns the range A1:A10 on Sheet1 to the variable. When src.Copy is executed, Excel places the contents of these cells onto the system clipboard. The crucial line is dest.PasteSpecial Paste:=xlPasteValues. Here, we are targeting cell B1, but because no size is specified for the paste operation, Excel automatically adjusts the destination range to match the dimensions of the source range. If your source is 10 rows high, the paste will fill B1:B10. Always remember to set Application.CutCopyMode = False. Without this line, the user interface remains in a "copy state," which can cause confusion for anyone interacting with the sheet while the macro runs or immediately after. It also frees up system resources associated with holding large amounts of data in the clipboard buffer.

Advanced Method: Direct Assignment for Performance

While PasteSpecial is versatile, it is not always the fastest method, especially when dealing with large datasets. An alternative and often more efficient approach is direct assignment using the Value property. This method bypasses the clipboard entirely, which eliminates the overhead of managing clipboard state and reduces the risk of errors related to external data sources.
Sub FastValueTransfer()
    Dim src As Range
    Dim dest As Range
    
    Set src = ThisWorkbook.Sheets("Data").Range("C5:C1000")
    Set dest = ThisWorkbook.Sheets("Report").Range("A1")
    
    ' Assign values directly from source to destination
    dest.Resize(src.Rows.Count, src.Columns.Count).Value = src.Value
    
    ' Optional: Preserve number formats if needed
    ' dest.NumberFormat = src.NumberFormat
End Sub
This technique uses the Resize property to ensure the destination range matches the dimensions of the source range exactly. By assigning src.Value to dest.Value, you are performing a pure data transfer. This is particularly useful when you are moving data between different worksheets or workbooks within the same instance of Excel. Note that this method does not carry over formatting. If you need both values and formats, you would need to combine this with a separate formatting step or revert to the PasteSpecial method described earlier. For more complex workflows involving scheduled tasks, you might want to integrate this logic into a larger automation sequence. You can explore how to schedule these operations effectively by checking out [VBA - Schedule tasks on oddly particular days](/news/1060605/vba-schedule-tasks-on-oddly-particular-days). Additionally, if your goal is to paste values based on user interaction, such as a dropdown selection, you may find relevant patterns in [Excel: Formula/Code to Paste Specific Values Based on Dropdown](/news/1044326/excel-paste-values-based-on-dropdown).

Handling Errors and Edge Cases

When automating copy-paste operations, several edge cases can cause macros to fail. One common issue is attempting to copy a range that includes merged cells. Merged cells can behave unpredictably during copy operations, sometimes resulting in partial pastes or runtime errors. To avoid this, ensure your source ranges are clean and unmerged before executing the copy command. Another consideration is hidden rows or columns. The Copy method includes hidden cells by default. If you only want to copy visible cells, you should modify the source range using the SpecialCells method with the xlCellTypeVisible constant. This ensures that your automation respects the current view state of the worksheet. Furthermore, always validate that the destination range exists and is writable. If the destination is locked or protected, the PasteSpecial action will throw a permission error. In production environments, it is wise to wrap these operations in an error handler to provide meaningful feedback to the user if the paste fails due to protection settings or invalid ranges.

Frequently Asked Questions

Does PasteSpecial xlPasteValues keep the original number format?

No, xlPasteValues strips away all formatting, including number formats, fonts, colors, and borders. It transfers only the raw data. If you need to retain the visual appearance of the numbers while discarding formulas, you must apply the source range's number format to the destination range separately after pasting the values.

Why is my macro slow when copying large ranges?

Copying large ranges via the clipboard can be slow because Excel has to manage the data in the system clipboard and update the screen. Using direct value assignment (dest.Value = src.Value) is generally much faster because it operates entirely in memory without touching the clipboard or triggering screen updates. Disabling screen updating via Application.ScreenUpdating = False at the start of your macro can also significantly improve performance.

Can I copy values from one workbook to another using this method?

Yes, the Copy and PasteSpecial methods work seamlessly across different workbooks, provided they are both open in the same Excel instance. You simply need to fully qualify your range objects with the correct Workbook and Worksheet references to ensure Excel knows exactly where the source and destination data reside.

What happens if I forget to turn off CutCopyMode?

If you do not set Application.CutCopyMode = False, the "marching ants" animation will remain around the copied cells. While this does not affect the functionality of subsequent macros, it can be visually distracting for users and may lead to accidental overwrites if the user inadvertently selects a new range while the clipboard is still active.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More