Disable Range Selection

Muninn Crow

New Member
Joined
Jul 7, 2008
Messages
3
Hi, I'm trying to make it so that the user cannot select certain cells of a worksheet. I've gotten it so that they can't select individual cells, right now if those cells are colored black, and if they try it simply returns their selection to wherever it was before they tried, but unfortunately, you can still click, hold, and drag the cursor to select a range, which can include these black cells. Is there a way to prevent the user from being able to select a range of cells, or a way to at least prevent them from selecting a range that includes one or more black cells?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
If selection by cursor or mouse is a black colored cell shift that selection one cell right.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Sheet module code, like: Sheet1.

If Target.Interior.ColorIndex = 1 Then Target.Offset(0, 1).Select
End Sub
 
Upvote 0
Yea, that works the same as what I have so far. If it's just one black cell that you select, then it moves the selection over one. But it still allows the user to select a range that includes black cells. If the range is ENTIRELY black cells, it will move over, but if even one cell isn't black, it doesn't act.

I don't know VB that well, but is there maybe a way to prevent the user from selecting cells at all with the mouse? Could I disable the mouse selection of cells, and disable the shift key altogether?
 
Upvote 0
This will work on single selections or selections of more than one cell. If any cell in the selection is colored black the selection is offset:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Sheet module code, like: Sheet1.

If Target.Count = 1 Then
If Target.Interior.ColorIndex = 1 Then Target.Offset(0, 1).Select
End If

If Target.Count > 1 Then

For Each Cell In Target
If Cell.Interior.ColorIndex = 1 Then ActiveCell.Select
Next Cell
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,630
Members
449,041
Latest member
Postman24

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