Copy and Pasting locks my unlocked cells

travisc

Board Regular
Joined
Oct 19, 2005
Messages
138
I have a program that generates a generic spreadsheet. When I copy the data from this sheet, and paste it in my "pretty" spreadsheet, it changes the formats in my sheet, and also locks the cells (Since the generic's cells are locked)... I protect all my sheets so other people at work can't modify any formulas or anything, so when it locks those cells, i have to unprotect the sheet to delete them.

What I need to know is how can I NOT allow copy and paste to change my cell formats? I already "Protect" my work sheets.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Can we see the code?

Perhaps you could use PasteSpecial to only copy the values.
 
Upvote 0
When I say "program" I don't mean my own, it's a program my company uses. I have no code, just general cut & paste... I know I can use "Paste Special" --> Values... but when I have a lot of factory workers using this I don't want them to be able to screw it up by pasting new formats, know what I mean? I know many of them would just hit "Paste" and not paste special.
 
Upvote 0
Here are some subs that i use to diable paste and paste special and run my own version using paste values. You can also assign Cntrl V to the macro.

Code:
Sub AddItemToShortcut()
Dim NewItem As CommandBarControl
Dim FileCheck As Boolean
    RemoveItemFromShortcut
    Set NewItem = CommandBars("Cell").Controls.Add
    With NewItem
        .Caption = "Paste Values"
        .OnAction = "pastevalues"
        .BeginGroup = True
    End With
End Sub

Code:
Sub RemoveItemFromShortcut()
On Error Resume Next
    CommandBars("Cell").Controls("Paste Values").Delete
End Sub

Code:
Sub InitView()
    SetBars (xlOn)
    With CommandBars("Cell")
        .Controls("Paste").Enabled = False
        .Controls("Paste Special...").Enabled = False
    End With
End Sub

Code:
Sub ExitView()
    With CommandBars("Cell")
        .Controls("Paste").Enabled = True
        .Controls("Paste Special...").Enabled = True
    End With
End Sub

Code:
Sub pastevalues()
 On Error GoTo ERRORHANDLER
 Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
 Application.CutCopyMode = False
Exit Sub
ERRORHANDLER:
    If err = 1004 Then
        Resume Next
    Else
        Debug.Print Error
        Resume Next
    End If
End Sub
[/code]
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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
Back
Top