To clear Excel’s copy mode after a VBA copy-and-paste operation, run Application.CutCopyMode = False after the paste. This removes Excel’s moving dashed border and ends its active Cut or Copy mode; it does not guarantee that the copied data is erased from the Windows clipboard or every clipboard history.
What “clear the clipboard” means in Excel
The phrase can refer to two different things. Excel’s copy mode is the application state that keeps the copied range active for another paste. Its familiar sign is the animated dashed outline, often called “marching ants,” around the source cells. Setting Application.CutCopyMode to False cancels that Excel state.
The Windows clipboard is the separate system facility used to transfer copied content between programs. Ending Excel’s copy mode is not the same as securely erasing everything held by Windows, clearing Windows clipboard history, or removing every entry in the Office Clipboard task pane. So if your goal is simply to stop Excel showing the copied-range outline, the VBA property is the right tool. If your goal is to remove clipboard data for privacy, do not assume that one line does that.
How Application.CutCopyMode works
Application.CutCopyMode reports or changes Excel’s Cut or Copy state. Setting it to False cancels that state. It is useful after a macro copies cells with Range.Copy and pastes them, because the macro can leave Excel ready to paste the same copied range again. Clearing the mode gives the user a clear end point and avoids leaving the source range outlined.
Place the assignment after the last paste that needs the copied content. If it runs before the paste, Excel no longer has the active copy operation needed for that paste. It is also reasonable to put the reset in a cleanup section so the mode is cancelled if the copy or paste encounters an error. It does not need to be run repeatedly; one reset after the operation is normally enough.
A complete copy-and-paste example
This example copies cells A2:C20 from a worksheet named Data to Archive, pasting values only. The destination begins at A2 and Excel fills the corresponding three-column, nineteen-row area. Change the worksheet names and ranges to match your workbook.
Sub CopyValuesAndClearCopyMode()
Dim sourceRange As Range
Dim destinationCell As Range
' Save a separate copy of the workbook before running this macro.
On Error GoTo CleanUp
Set sourceRange = ThisWorkbook.Worksheets("Data").Range("A2:C20")
Set destinationCell = ThisWorkbook.Worksheets("Archive").Range("A2")
sourceRange.Copy
destinationCell.PasteSpecial Paste:=xlPasteValues
CleanUp:
' End Excel's Cut or Copy mode, including after an error.
Application.CutCopyMode = False
If Err.Number <> 0 Then
MsgBox "Copy or paste failed: " & Err.Description, vbExclamation
End If
End Sub
The cleanup line is reached after a successful paste and if an error jumps to the cleanup label. The message reports a problem but does not roll back any changes already made. Macros cannot be undone with Ctrl+Z, so save a separate workbook copy before running one that changes data. To add this macro in desktop Excel for Microsoft 365 on Windows, press Alt+F11, choose Insert > Module in the Visual Basic Editor, and paste the code into the module. Save the workbook in a macro-enabled format such as .xlsm.
Choosing between Copy, direct assignment, and PasteSpecial
Not every transfer needs the clipboard. Choose the method based on what the destination should receive:
- Copy followed by PasteSpecial: Use this when you need selected elements such as values, formats, or formulas. In the example,
xlPasteValuespastes the displayed results rather than the source formulas. - Range.Copy with a Destination argument: For a straightforward range copy,
sourceRange.Copy Destination:=destinationCellcan copy directly to a destination without a separate paste command. It copies the range’s cells rather than limiting the transfer to values only. - Assign values directly: Assigning a source range’s
Value2to a same-sized destination range transfers the calculated cell values without using Copy and Paste. It does not copy formatting, comments, or formulas as formulas.
Direct assignment can be a good fit for a large values-only transfer because it avoids clipboard interaction. It is not a universal replacement for PasteSpecial: formulas, formatting, column widths, and other cell features may require a different approach. When a macro genuinely uses Copy and Paste, resetting Application.CutCopyMode afterward remains a simple way to close Excel’s copy state.
Excel’s clipboard, Windows history, and Office Clipboard
Windows and Office can expose clipboard content in more than one place. Windows clipboard history, when enabled, is opened with Windows key+V. It can hold recent copied items, so cancelling Excel’s copy mode should not be treated as clearing that history. Windows settings control clipboard history and its available clearing options; those settings are outside the scope of Application.CutCopyMode.
Excel for Windows also provides the Office Clipboard task pane, which can collect multiple copied items from Office applications. Open it from the small dialog launcher in the Home tab’s Clipboard group. The pane has a Clear All control for its collected list. That is a manual Office feature, not what the VBA property does, and clearing the pane should not be described as a guaranteed secure wipe of every clipboard location.
If the copied information is sensitive, the safest approach is to avoid copying it unnecessarily and follow your organization’s device and data-handling guidance. A macro that ends Excel copy mode is useful housekeeping, but it is not a data-erasure or security feature.
Common problems and how to avoid them
- The dashed outline remains: Check that the reset line runs after the final paste and that the macro reaches it. A runtime error that stops execution before the reset can leave Excel in copy mode; use a cleanup path such as the example.
- The paste fails after the reset: Confirm the reset is not placed between
CopyandPasteSpecial. Cancelling copy mode too early removes the pending Excel copy operation. - Copied content is still available elsewhere: That can be expected. The property cancels Excel’s Cut or Copy state; it does not promise to erase Windows clipboard history or all Office clipboard entries.
- The macro says a worksheet is missing: Worksheet names must match the workbook’s tab names, including spaces. The example uses
ThisWorkbook, meaning the workbook containing the VBA code; it may not be the same as whichever workbook happens to be active. - Ctrl+Z does not reverse the macro: Excel clears the normal undo stack when VBA changes the workbook. Keep a backup or make the macro work on a copy when the operation is difficult to reconstruct.
For a manual copy that you decide not to paste, press Esc to cancel Excel’s copy mode. This is a quick way to remove the moving border, but, like the VBA property, it should not be mistaken for clearing every system-level clipboard record.
Windows, Mac, and Excel for the web
The article’s instructions target desktop Excel for Microsoft 365 on Windows. VBA macros run in desktop Excel, not in Excel for the web, so the VBA code cannot be used in a browser workbook. In the web app, use the application’s available copy and paste controls; do not expect the Visual Basic Editor or VBA events to be available there.
Excel for Mac supports VBA, and Application.CutCopyMode = False is the Excel object-model approach to ending copy mode there as well. Keyboard shortcuts differ: Windows uses Alt+F11 to open the Visual Basic Editor, while Mac commonly uses Option+F11 (some keyboards require Fn as well). Mac clipboard behavior and available system history tools differ from Windows, so Windows key+V and Windows clipboard-history instructions do not apply. If a macro depends on Windows-specific API calls to manipulate the operating system clipboard, it needs separate Mac-specific handling; the simple Excel property avoids that platform-specific API approach.
Frequently Asked Questions
Does Application.CutCopyMode = False delete copied cells?
No. It cancels Excel’s active Cut or Copy mode; it does not delete the source cells or undo the paste. A prior paste remains in the destination unless the macro separately changes or clears those cells.
Does it clear the Windows clipboard?
It should not be relied on to do that. The property clears Excel’s copy state and marching-ants outline, but Windows clipboard history and other clipboard storage are separate. Use the appropriate Windows controls if you need to manage Windows history.
Where should I put the line in a macro?
Put it after the last paste that uses the copied range. For more reliable cleanup, route normal completion and error handling through a cleanup section that sets Application.CutCopyMode to False.
Can I stop the marching ants without VBA?
Yes. Press Esc after copying to cancel Excel’s current copy mode. This ends the pending operation, so do it only when you do not intend to paste that copied range again.
Why is the clipboard still available after the macro finishes?
Because Excel’s copy-mode indicator and the operating system’s clipboard are not identical. A copied item may remain available to another application or in a clipboard history even after Excel’s dashed outline disappears.
Related
- Excel Named Range Shortcut: Create, Edit, and Use Names
- Excel Page Break Dotted Lines: How to Move Them in Print
- Excel Merge Cells and Keep All Text Without Data Loss
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- VBA Range Type: What It Means and How to Use It in ExcelIn Excel VBA, Range is an object type: it represents one cell, a group of cells, or a…
- Excel VBA Copy an Entire Column: Safe Code and TipsYes. In Excel for Microsoft 365 on Windows, VBA can copy a complete column with a worksheet’s Columns…
- VBA Loop Through a Dictionary: Keys, Items, and ExamplesTo loop through a VBA Dictionary, use For Each key In dict.Keys, then read each value with dict(key).…
- Excel VBA Copy Paste Transpose: Working Code and TipsTo copy a range and paste it transposed with Excel VBA, copy the source range and use PasteSpecial…
- VBA Loops Within Loops: How Nested Loops Work in ExcelYes. VBA can run one loop inside another; this is called a nested loop. The outer loop runs…
- Excel VBA String Character Limit: What Really AppliesIn Excel VBA, a variable-length String can hold roughly 2 billion characters in theory, but available memory and…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.