ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Change background colour of selected cells (https://www.excelbanter.com/excel-programming/386211-re-change-background-colour-selected-cells.html)

Greg Wilson

Change background colour of selected cells
 
Paste this to the worksheet's code module:-

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.FormatConditions.Delete
With Target
If .Count 1 Then Exit Sub
.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
.FormatConditions(1).Interior.ColorIndex = 19
End With
End Sub

The downside of using worksheet event code is that it kills the contents of
the clipboard. You will notice that if you copy something and then attempt to
paste it to another cell the Paste button is grayed. You will need code to
correct this.

Alternatively, you can still drag and drop to cut and paste. And if you hold
down the Ctrl key and drag and drop it will copy and paste.

Regards,
Greg


"Redleg" wrote:

I wish to change the background colour of any selected cell on entry and
revert to original colour (none) on exit.



All times are GMT +1. The time now is 03:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com