Is there a way to change the background of a cell if a user initiates a CTRL+C or right clicks and selects Copy?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Change cell background color if cell is copied.
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Change cell background color if cell is copied.
- This topic has 9 replies, 4 voices, and was last updated 9 years ago.
Viewing 7 reply threadsAuthorReplies-
Maudibe
AskWoody_MVPJune 11, 2016 at 2:27 am #1567225KW,
Here is the code to do what you want. If the user right clicks on a cell or range of cells then selects copy, the cell(s) turn red. The same occurs if CTRL-C is used to copy.
HT,
MaudCopy to ThisWorkbook Module:
Code:Private Sub Workbook_Deactivate() [COLOR=”#008000″]’———————————- ‘REMOVES CUSTOM CONTEXT MACRO AND RESETS CONTEXT MENU BACK TO DEFAULT[/COLOR] On Error Resume Next With Application .CommandBars(“Cell”).Controls(“&Copy”).Delete .CommandBars(“Cell”).Reset End With Application.MacroOptions Macro:=”CheckCopy”, Description:=””, ShortcutKey:=”” On Error GoTo 0 End Sub Private Sub Workbook_Open() [COLOR=”#008000″]’———————————- ‘SETS CTRL-C TO RUN THE CHECKCOPY MACRO[/COLOR] Application.MacroOptions Macro:=”CheckCopy”, Description:=””, ShortcutKey:=”c” End Sub Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) [COLOR=”#008000″]’———————————- ‘CREATES CUSTOM CONTEXT MACRO[/COLOR] Dim MyMacro As CommandBarButton On Error Resume Next With Application .CommandBars(“Cell”).Reset .CommandBars(“Cell”).Controls(“&Copy”).Delete Set MyMacro = .CommandBars(“Cell”).Controls.Add(Temporary:=True) End With With MyMacro .Caption = “&Copy” .Move Before:=2 .Style = msoButtonCaption .OnAction = “CheckCopy” End With On Error GoTo 0 End Sub
Copy to a Standard module:
Code:Public Sub CheckCopy() [COLOR=”#008000″]’———————————- ‘COPY FUNCTION AND CELL COLOR CHANGE[/COLOR] Selection.Copy Selection.Interior.Color = vbRed End Sub
-
zeddy
AskWoody_MVPJune 11, 2016 at 3:16 am #1567226KW
It’s not entirely clear what you want.
Maud shows one way (but in the posted sample file it would still be possible to copy cells to another location without setting the red cell backgrounds).What if the User presses Ctrl-C and then cancels with an Esc?
Do you want both the copied source-cells and the destination-cells to be red, or just the destination-cells?zeddy
-
krweaver
AskWoody LoungerJune 11, 2016 at 5:57 am #1567234I only want the source cells to change color. Maud’s version changes both the source and destination cells. The user copies a block of cells, pastes them into another workbook, then returns to the original worksheet. Once back on the original, she wants to have kept track automatically which ones she copied.
You brought up an interesting issue of doing a copy then cancel it. I can see that happening if she selects the wrong cells and cancels before pasting into the other workbook.
-
Maudibe
AskWoody_MVP -
RetiredGeek
AskWoody_MVPJune 11, 2016 at 9:29 am #1567245Maud,
Nice piece of coding! :thewave: :cheers:
-
Maudibe
AskWoody_MVP -
zeddy
AskWoody_MVPJune 11, 2016 at 10:51 am #1567272Hi Maud
When I used your file, I found that copying any cells to the same sheet made the source cells red.
When I copied cells to another workbook, the destination cells were also red.
If I selected a group of cells, pressed Ctrl-C for Copy, then [Esc] to cancel, it still left some cells red.I used a different method in the attached workbook.
In my version, cell formats of copied-cells are preserved when copied to a destination workbook.
Copying cells on the same source sheet doesn’t affect their formats.
It’s only when copying to a another workbook that they are ‘turned red’
..and if you try and cheat, i.e. select a group of cells to copy, then switch to another workbook, but then decide not to do anything (i.e. didn’t do the copy), then when you come back to the source workbook, the source cells are NOT turned red.It’s not perfect (I still know a way of copying cells from the source to a destination workbook which bypasses the wanted change to the cell background)
zeddy
-
Maudibe
AskWoody_MVPJune 11, 2016 at 1:23 pm #1567296Here is a revision that allows pasting to the existing sheet, a different sheet, or a different workbook without carrying the formatting to the destination cells. The only caveat is that when you copy the cell(s), you do not get the copy mode dotted lines around the copied cells. Pasting the data remains unchanged.
Maud
-
zeddy
AskWoody_MVPJune 11, 2016 at 2:38 pm #1567301Hi Maud
From KW’s post#4:
The user copies a block of cells, pastes them into another workbook, then returns to the original worksheet.
I cannot copy a block of cells from the source file to a new workbook.
If I try to copy multiple cells, then cancel with [Esc], it marks some of the cells as being ‘copied’ when they haven’t been. It seems to only assume one cell is being copied.If my source cells have any formatting (e.g. font, color etc etc ) these are not copied to the destination workbook.
..and if I cancel a ‘copy’, I lose the original cell formats.
I thought my posted version dealt with this OK.zeddy
-
Viewing 7 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
AMD : Out of Bounds (OOB) read vulnerability in TPM 2.0 CVE-2025-2884
by
Alex5723
10 hours, 29 minutes ago -
Totally remove or disable BitLocker
by
CWBillow
9 hours, 23 minutes ago -
Windows 10 gets 6 years of ESU?
by
n0ads
6 hours, 12 minutes ago -
Apple, Google stores still offer China-based VPNs, report says
by
Nibbled To Death By Ducks
21 hours, 16 minutes ago -
Search Forums only bring up my posts?
by
Deo
21 hours, 29 minutes ago -
Windows Spotlight broken on Enterprise and Pro for Workstations?
by
steeviebops
1 day, 8 hours ago -
Denmark wants to dump Microsoft for Linux + LibreOffice
by
Alex5723
1 day, 1 hour ago -
How to get Microsoft Defender to honor Group Policy Setting
by
Ralph
1 day, 9 hours ago -
Apple : Paragon’s iOS Mercenary Spyware Finds Journalists Target
by
Alex5723
1 day, 19 hours ago -
Music : The Rose Room – It’s Been A Long, Long Time album
by
Alex5723
1 day, 20 hours ago -
Disengage Bitlocker
by
CWBillow
1 day, 10 hours ago -
Mac Mini M2 Service Program for No Power Issue
by
Alex5723
1 day, 22 hours ago -
New Win 11 Pro Geekom Setup questions
by
Deo
21 hours, 25 minutes ago -
Windows 11 Insider Preview build 26200.5651 released to DEV
by
joep517
2 days, 6 hours ago -
Windows 11 Insider Preview build 26120.4441 (24H2) released to BETA
by
joep517
2 days, 6 hours ago -
iOS 26,, MacOS 26 : Create your own AI chatbot
by
Alex5723
2 days, 10 hours ago -
New PC transfer program recommendations?
by
DaveBoston
14 hours, 55 minutes ago -
Windows 11 Insider Preview Build 22631.5545 (23H2) released to Release Preview
by
joep517
2 days, 14 hours ago -
Windows 10 Build 19045.6029 (22H2) to Release Preview Channel
by
joep517
2 days, 14 hours ago -
Best tools for upgrading a Windows 10 to an 11
by
Susan Bradley
2 days, 2 hours ago -
The end of Windows 10 is approaching, consider Linux and LibreOffice
by
Alex5723
1 day, 6 hours ago -
Extended Windows Built-in Disk Cleanup Utility
by
bbearren
1 day, 15 hours ago -
Win 11 24H2 June 2025 Update breaks WIFI
by
dportenlanger
3 days, 9 hours ago -
Update from WinPro 10 v. 1511 on T460p?
by
CatoRenasci
2 days, 6 hours ago -
System Restore and Updates Paused
by
veteran
3 days, 11 hours ago -
Windows 10/11 clock app
by
Kathy Stevens
2 days, 22 hours ago -
Turn off right-click draw
by
Charles Billow
3 days, 14 hours ago -
Introducing ChromeOS M137 to The Stable Channel
by
Alex5723
3 days, 18 hours ago -
Brian Wilson (The Beach Boys) R.I.P
by
Alex5723
6 hours, 46 minutes ago -
Master patch listing for June 10, 2025
by
Susan Bradley
3 days, 19 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.