when paste, paste values only

zico8

Board Regular
Joined
Jul 13, 2015
Messages
225
Hi,

I would like to set my sheet that only copying values is allowed.

I know I should use
Code:
.PasteSpecial xlPasteValues
, but how should I use it if I want to paste values only when user will try to paste something into cell?
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
try this

goes in SHEET module (right-click on sheet tab \ View Code \ paste in code window)
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    On Error Resume Next
    Set rng = Target.SpecialCells(xlCellTypeFormulas)
    If Not Intersect(rng, Target) Is Nothing Then
        Select Case Application.CommandBars("Standard").Controls("&Undo").List(1)
            Case "Paste Special", "Auto Fill": rng.Value = rng.Value
        End Select
    End If
End Sub
 
Upvote 0
Please ignore my previous effort :oops:
- try this instead

goes in SHEET module (right-click on sheet tab \ View Code \ paste in code window)
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim x, rng As Range, last As String
    On Error Resume Next
    Set rng = Target.SpecialCells(xlCellTypeFormulas)
    last = Application.CommandBars("Standard").Controls("&Undo").List(1)
    If Not Intersect(rng, Target) Is Nothing Then
        If Left(last, 5) = "Paste" Or last = "Auto Fill" Then
             x = Target.Value
             Application.Undo
             Target.Value = x
        End If
    End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,602
Members
449,089
Latest member
Motoracer88

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