VBA & Macro Problems

Copy Excel Values and Number Formats via VBA Without Overwriting Conditional Formatting

Camila MilosovichCamila Milosovich Nov 3, 2026 869 views

Question details

The user needs a VBA macro to copy cell values and number formats from a source column to a destination column while preserving the destination's existing conditional formatting.

Copy Excel Values and Number Formats via VBA Without Overwriting Conditional Formatting
Product
Excel
Device & OS
not provided
Scenario
Writing a VBA macro to automate data transfer between columns without affecting existing rule-based cell formatting.
Observed behavior
Standard copy-pasting via VBA overwrites the destination's conditional formatting and leaves the selection in an active copy mode with a moving border.
Before you start

Ensure your Excel file is saved as a Macro-Enabled Workbook (.xlsm) and that you have enabled Developer tools to run VBA code safely.

Solution 1Recommended

Use PasteSpecial with xlPasteValuesAndNumberFormats

This method copies only the values and the number formats, leaving the conditional formatting rules at the destination completely untouched.

Using the default copy and paste method in VBA transfers all cell properties, including conditional formatting rules. To prevent this, the PasteSpecial method allows you to specify exactly what attributes to paste.

1
Open the VBA Editor

Press Alt + F11 to open the Visual Basic for Applications (VBA) editor in Excel.

2
Locate Your Macro

Insert a new module or open the existing module where your macro is stored.

3
Write the Copy Command

Use the .Copy method on your source range. For example: Range("C3:C10").Copy

4
Apply the PasteSpecial Method

Use the .PasteSpecial method on the destination range with the argument xlPasteValuesAndNumberFormats. For example: Range("O3").PasteSpecial Paste:=xlPasteValuesAndNumberFormats

5
Clear the Copy Mode

Add the line Application.CutCopyMode = False immediately after the paste command to clear the moving copy border and automatically exit copy mode.

Use PasteSpecial with xlPasteValuesAndNumberFormats
Clear Copy Mode: Always use Application.CutCopyMode = False to prevent the copy buffer from remaining active in the background and deselect the copied range.
Advanced Macros in WPS Spreadsheet

Automate Data Transfer with WPS Spreadsheet VBA

WPS Spreadsheet offers built-in VBA support, allowing you to write, edit, and execute macros seamlessly. You can perform advanced operations like PasteSpecial to copy values and number formats without disrupting conditional formatting.

  1. 1. Access Developer Tools: Open WPS Spreadsheet and navigate to the 'Developer' tab on the top ribbon.
  2. 2. Launch the VB Editor: Click 'VB Editor' to open the macro programming environment.
  3. 3. Write the Macro: Enter your VBA script using the .PasteSpecial xlPasteValuesAndNumberFormats command exactly as you would in Microsoft Excel.
  4. 4. Run the Automation: Run the macro to automatically copy your values and formats while keeping the target conditional formatting intact.
Fully compatible with Microsoft Excel VBA syntaxSupports complex conditional formatting rulesHigh performance for large data automationLightweight and free to use
microsoft office alternative - wps office

Frequently Asked Questions

What happens if I use xlPasteValues instead of xlPasteValuesAndNumberFormats?

Using xlPasteValues will only paste the raw data. Any specific number formats (like currency symbols, dates, or decimal places) from the source cells will be lost, and the data will adopt the destination cell's default format.

Can I preserve column widths when using PasteSpecial in VBA?

Yes, but it requires an additional step. You must perform another PasteSpecial command using Paste:=xlPasteColumnWidths on the destination range right after pasting the values.

Why does a moving border remain around my copied cells after running the macro?

The moving border (or "marching ants") indicates that the application is still in copy mode. Adding Application.CutCopyMode = False at the end of your VBA script safely clears this state.