Restrict Pasting Into A column

elenakotanchyan

New Member
Joined
Jul 13, 2023
Messages
10
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Web
Hi,

I am providing clients with feedback on their reports. I send them excel file where they input their response in one column. I have noticed that they copy and paste some of my responses instead of just typing out their own response. I was able to deactivate copy and paste on the entire worksheet but I was wondering if there is a way to use VBA code to deactivate pasting into a specified cell range (in my case E6:E504) and not the entire workbook/worksheet?

Thank you!
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Welcome to the Board!

You could create automated VBA code that would undo the last action whenever they try to update a cell in the range E6:E504 (will work for manual updates, or copy/paste).
To apply code like that, go to the sheet you wish to apply it to, right-click on the sheet tab name at the bottom of the screen, select "View Code", and paste this VBA code in the VB Editor window that pops up:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range
    
'   See if any cells updated in range
    Set rng = Intersect(Range("E6:E504"), Target)
    If Not rng Is Nothing Then
        Application.EnableEvents = False
        Application.Undo
        Application.EnableEvents = True
        MsgBox "You are not allowed to update range E6:E504"
    End If
        
End Sub
Then try to make changes to the range E6:E504 and see what happens.

The only caveat with this is that they need to enable VBA/Macros on the workbook in order for the code to run.
 
Upvote 0
Welcome to the Board!

You could create automated VBA code that would undo the last action whenever they try to update a cell in the range E6:E504 (will work for manual updates, or copy/paste).
To apply code like that, go to the sheet you wish to apply it to, right-click on the sheet tab name at the bottom of the screen, select "View Code", and paste this VBA code in the VB Editor window that pops up:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range
   
'   See if any cells updated in range
    Set rng = Intersect(Range("E6:E504"), Target)
    If Not rng Is Nothing Then
        Application.EnableEvents = False
        Application.Undo
        Application.EnableEvents = True
        MsgBox "You are not allowed to update range E6:E504"
    End If
       
End Sub
Then try to make changes to the range E6:E504 and see what happens.

The only caveat with this is that they need to enable VBA/Macros on the workbook in order for the code to run.

Hi,

Thank you so much for your response! This code works.

However, this disables any kind of changes to the range. I want to only disable pasting into that range and leave the ability to manually type in the text. Do you know how I should do it?

Appreciate your help!
 
Upvote 0
OK, I stole some code from here to amend my original code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range
    Dim UndoList As String
   
'   See if any cells updated in range
    Set rng = Intersect(Range("E6:E504"), Target)
   
'   Exit if no cells in watched range update
    If rng Is Nothing Then Exit Sub
   
'   Get the undo List to capture the last action performed by user
    UndoList = Application.CommandBars("Standard").Controls("&Undo").List(1)
   
'   See if last action was paste
    If Left(UndoList, 5) = "Paste" Then
        Application.EnableEvents = False
        Application.Undo
        Application.EnableEvents = True
        Application.CutCopyMode = False
        MsgBox "You are not allowed to paste to range E6:E504"
    End If
       
End Sub
 
Upvote 0
Solution
OK, I stole some code from here to amend my original code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range
    Dim UndoList As String
  
'   See if any cells updated in range
    Set rng = Intersect(Range("E6:E504"), Target)
  
'   Exit if no cells in watched range update
    If rng Is Nothing Then Exit Sub
  
'   Get the undo List to capture the last action performed by user
    UndoList = Application.CommandBars("Standard").Controls("&Undo").List(1)
  
'   See if last action was paste
    If Left(UndoList, 5) = "Paste" Then
        Application.EnableEvents = False
        Application.Undo
        Application.EnableEvents = True
        Application.CutCopyMode = False
        MsgBox "You are not allowed to paste to range E6:E504"
    End If
      
End Sub

This is awesome! Just what I need! I really appreciate your help!
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,215,329
Messages
6,124,302
Members
449,150
Latest member
NyDarR

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