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

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)
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,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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