Restrict Specific cell in specific sheet to manual entries ONLY i.e. NO paste of any kind!

Pobek

Board Regular
Joined
Jul 7, 2015
Messages
89
Can someone please help with constructing a code that will enable me to restrict any form of pasting (ctrl V or right click) in a specific cell.

NOTE:
This cell is an access signIn area and as a result, the status bar disappears when you click on it (to avoid situations where onlookers can see the access code of different users during entry in the formula bar).

Is there a way that we can restrict this paste function without jeopardizing the existing formula-bar disappearing setting??
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Change the cell (in red) to suit you needs. Close the code window to return to your sheet.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("[COLOR="#FF0000"]A1[/COLOR]")) Is Nothing Then
        Application.CutCopyMode = False
    Else
        Application.CutCopyMode = True
    End If
End Sub
 
Upvote 0
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Change the cell (in red) to suit you needs. Close the code window to return to your sheet.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("[COLOR=#FF0000]A1[/COLOR]")) Is Nothing Then
        Application.CutCopyMode = False
    Else
        Application.CutCopyMode = True
    End If
End Sub





Thanks,

But I already had this in there and it does not work:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count = 1 Then
If Not Intersect(Target, Range("Tauthcod")) Is Nothing Then
Application.DisplayFormulaBar = False
Application.CutCopyMode = False
Else
Application.DisplayFormulaBar = True
Application.CutCopyMode = True
End If
End If
End Sub


Any suggestions ... ?
 
Upvote 0
I tried this version using a specific cell (A1) instead of a named range ("Tauthcod") and it worked as you requested.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Count = 1 Then
        If Not Intersect(Target, Range("[COLOR="#FF0000"]A1[/COLOR]")) Is Nothing Then
            Application.DisplayFormulaBar = False
            Application.CutCopyMode = False
        Else
            Application.DisplayFormulaBar = True
            Application.CutCopyMode = True
        End If
    End If
End Sub
 
Upvote 0
Very odd, just tried it again using I23 and still no show. I am copying the code from an email and pasting and its overwriting the cell. Really odd!
 
Upvote 0
I just realized that the Application.CutCopyMode = False applies only to the "Application" which happens to be Excel so it doesn't apply to anything copied outside of Excel. After a little research, I found this work-around that seems to work. Place the following code in a standard module. This code basically empties the clipboard regardless of where the data is copied from.
Code:
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function EmptyClipboard Lib "user32" () As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Place this macro in the code module for the worksheet and change the cell:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("[COLOR="#FF0000"]A1[/COLOR]")) Is Nothing Then
        OpenClipboard (0&)
        EmptyClipboard
        CloseClipboard
        Application.DisplayFormulaBar = False
        Application.CutCopyMode = False
    Else
        Application.DisplayFormulaBar = True
        Application.CutCopyMode = True
    End If
End Sub
 
Upvote 0
Very good! Nearly there!!

So this code stops any form of pasting which is good. However, if the cell (Tauthcode) iss already selected (prior to the copy)... it actually allows the paste. Tried forcing the command to go out and back into the tauthcode cell on the private function run but that only causes issues and errors.

Any addtional ideas :)

We nearly there ...
 
Upvote 0
Delete the code you previously placed in the standard module and place these 2 macros in the worksheet code module:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim lastAction As String
    Application.ScreenUpdating = False
    If Not Intersect(Target, Range("A1")) Is Nothing Then
        lastAction = Application.CommandBars("Standard").Controls("&Undo").List(1)
        If Left(lastAction, 5) = "Paste" Then
            Application.Undo
        End If
    End If
    Application.ScreenUpdating = True
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("A1")) Is Nothing Then
        Application.DisplayFormulaBar = False
    Else
        Application.DisplayFormulaBar = True
    End If
End Sub
 
Upvote 0
code falls over on this line ...


lastAction = Application.CommandBars("Standard").Controls("&Undo").List(1)
 
Upvote 0
The macro worked properly for me when I tested it. I'm afraid I don't know why it's not working for you. Perhaps you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0

Forum statistics

Threads
1,216,091
Messages
6,128,775
Members
449,468
Latest member
AGreen17

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