how can i disable/enable "copy and past" in excel sheet?

A

Aman

Can you help me with VBA code? because i want t keep the formatting and
condition on cells as i did and disable the user to use copy and past from
another unformatted cell
 
G

Gord Dibben

Place this code in the worksheet module.

Private Sub Worksheet_Change(ByVal Target As Range)
'retain formatting when a cell is copied over
Dim myValue
With Application
.EnableEvents = False
myValue = Target.Value
.Undo
Target = myValue
.EnableEvents = True
End With
Application.CutCopyMode = False
End Sub

Note: will crash if cells are "cut" rather than copied.


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top