ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   copy & paste from other worksheet - but not allow to cut (https://www.excelbanter.com/excel-programming/296580-copy-paste-other-worksheet-but-not-allow-cut.html)

No Name

copy & paste from other worksheet - but not allow to cut
 
I have a formatted area I try to keep right formatted! I have tried to use
conditional formatting, but when you paste a cell from an other worksheet,
that format follow.

I have tried to use the frequent suggested funktion DisableCutAndPaste
below, but it doesn't allow me to copy & paste! I tried to disable some of
the controls, but can't find it to work. Please help me! I enclose the whole
code for the specific sheet (Blad101) if there are any of the other subs who
cause any trouble.

Thank you for any help!


Private Sub Worksheet_Activate()
ActiveSheet.Unprotect
Call DisableCutAndPaste

If Blad101.Range("O13") = 1 Then
Call GomTommaRader_B_4_125 ' hide rows sub if
checkbox = 1

ElseIf Blad101.Range("O13") = 0 Then
Call TaFramRad_Alla 'unhide rows
if checkbox = 0
End If

ActiveSheet.Protect AllowFormattingCells:=False
ActiveSheet.EnableSelection = xlUnlockedCells


End Sub
Private Sub Worksheet_Deactivate()
Call EnableCutAndPaste

End Sub

Sub DisableCutAndPaste()
EnableControl 21, False ' cut
'EnableControl 19, False ' copy
'EnableControl 22, False ' paste
'EnableControl 755, False ' pastespecial
'Application.OnKey "^c", ""
'Application.OnKey "^v", ""
'Application.OnKey "+{DEL}", ""
'Application.OnKey "+{INSERT}", ""
Application.CellDragAndDrop = False
End Sub

Sub EnableCutAndPaste()
EnableControl 21, True ' cut
EnableControl 19, True ' copy
EnableControl 22, True ' paste
EnableControl 755, True ' pastespecial
Application.OnKey "^c"
Application.OnKey "^v"
Application.OnKey "+{DEL}"
Application.OnKey "+{INSERT}"
Application.CellDragAndDrop = True
End Sub

Sub EnableControl(Id As Integer, Enabled As Boolean)
Dim CB As CommandBar
Dim C As CommandBarControl
For Each CB In Application.CommandBars
Set C = CB.FindControl(Id:=Id, recursive:=True)
If Not C Is Nothing Then C.Enabled = Enabled
Next
End Sub





All times are GMT +1. The time now is 05:20 PM.

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