paste and paste special greyed out

methody

Well-known Member
Joined
Jun 17, 2002
Messages
841
Hello there

The paste and paste special options are greyed out on a reasonably complex workbook which I am using.

I have managed to isolate the problem to the piece of code below. The code makes the colour of a selected cell change colour. can anyone explain why this code remove these options and can anyone suggest how to adjust the code so that the paste and paste special options are not greyed out.
thanks

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim nm As Name, rng As Range
On Error Resume Next
Set nm = ThisWorkbook.Names("CellAddress")
On Error GoTo 0
Set rng = Intersect(Target, Range("I15:I588"))
If Not nm Is Nothing Then nm.RefersToRange.Interior.Color = vbDarkBlue
If Not rng Is Nothing Then
If rng.Count = 1 Then
On Error Resume Next
nm.Delete
On Error GoTo 0
ThisWorkbook.Names.Add "CellAddress", rng
rng.Interior.Color = vbRed
End If
End If

End Sub
 

Some videos you may like

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
This line:

If Not nm Is Nothing Then nm.RefersToRange.Interior.Color = vbDarkBlue

clears the clipboard (if the interior colour is set).
 

methody

Well-known Member
Joined
Jun 17, 2002
Messages
841
thank you
Is there anyway of retain the retaining the ability to change the cell colour without having the options greyed.
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
I don't think so. I don't know a way to establish what was on the clipboard so that it could be put back there.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,514
Messages
5,596,611
Members
414,080
Latest member
penguin23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top