Restrict Sheet Use to Certain Columns of Table

neodjandre

Well-known Member
Joined
Nov 29, 2006
Messages
950
Office Version
  1. 2019
Platform
  1. Windows
I am using this code which works fine to restrict selection of one cell in a sheet.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Target.Range("A1").Select
Application.CutCopyMode = False
End Sub


However, I need to modify this so that the restriction only applies to certain table columns (and not the whole sheet).

e.g.

Range("table_a
Code:
")
Range("table_b[Name]")

Any ideas? many thanks
 
Last edited:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
neojandre,

first a comment: you have been posting on this forum long enough to know that you should use code brackets around your code (see below in red). A lot of regulars won't even answer questions where code brackets are not used. Please do. It makes your code easier to read and to copy.

What you are trying to achieve can be done in the code shown below, but could posssibly also be done using cell properties - protection and the protecting the worksheet.

The method you are using stops copy/paste from these cells, but the user can still copy down by dragging.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("B2:B50")) Is Nothing Or _
       Not Intersect(Target, Columns("D")) Is Nothing Then    ' Add / amend for the ranges you want to protect
        Target.Range("A1").Select
        Application.CutCopyMode = False
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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