prevent cell selection in certain areas

robertvdb

Active Member
Joined
Jan 10, 2021
Messages
327
Office Version
  1. 2016
Platform
  1. Windows
is there a way to prevent cell selection in columns A,B,D,E (see attached image) WITHOUT using Sheet Protection or WITHOUT using the Worksheet Selection Change below ?

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim i, j As Integer
i = Target.Row
j = Target.Column

'If Target.CountLarge > 1 Then Exit Sub
   
Application.EnableEvents = False

If i < 2 Then
    Cells(2, 2).Select
End If

If i > 10 Then
    Cells(10, 2).Select
End If

If i >= 2 And i <= 10 Then
    If j < 3 Then Cells(i, 3).Select
    If j > 3 Then Cells(i, 3).Select
End If

Application.EnableEvents = True

End Sub
 

Attachments

  • column_C_only.png
    column_C_only.png
    22.8 KB · Views: 6

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Not without selection change. But this would work with just a little code like below.
Try this:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Select Case Target.Column
Case 1, 2, 4, 5: MsgBox "Your not allowed in columns" & vbNewLine & "1,2,4,5"
End Select

End Sub
 
Upvote 0
Try this I made this modification.
Use this script.
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Select Case Target.Column
Case 1, 2, 4, 5: MsgBox "Your not allowed in columns" & vbNewLine & "1,2,4,5"
Cells(1, 6).Select
End Select

End Sub
 
Upvote 0
Thanks, I appreciate your script, which is significantly shorter than mine.

However, I'm still hoping to avoid SelectionChange...
 
Upvote 0

Forum statistics

Threads
1,216,073
Messages
6,128,645
Members
449,461
Latest member
kokoanutt

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