Don't allow multiple selections

Chewyhairball

Active Member
Joined
Nov 30, 2017
Messages
312
Office Version
  1. 365
Platform
  1. Windows
Hi Guys

I have this bit of code that doesn't allow you to select anymore than 1 cell at a time.

I am trying to adapt it so it only works in the range C13:T13 and doesn't allow more than 3 cells selected within this range.

any help is appreciated.

thanks

Rory
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 '>> Prevent user from multiple selection before any changes:
 
 If Selection.Cells.Count > 1 Then
 MsgBox "Sorry, multiple selections are not allowed.", vbCritical
 ActiveCell.Select
 Exit Sub
 End If
 
End Sub
 

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)
Hi, for starters :​
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Dim Rg As Range
        Set Rg = Intersect([C13:T13], Target)
     If Not Rg Is Nothing Then
         If Rg.Count > 3 Then Beep: ActiveCell.Select
        Set Rg = Nothing
     End If
End Sub
 
Upvote 0
Solution
Another option
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   Dim Rng As Range
   
   Set Rng = Intersect(Target, Range("C13:T13"))
   If Rng Is Nothing Then Exit Sub
   If Rng.Count > 3 Or Rng.Count <> Target.Count Then
      MsgBox "Sorry, multiple selections are not allowed.", vbCritical
      ActiveCell.Select
   End If
End Sub
This will prevent selecting a range like C12:D14
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,186
Members
449,071
Latest member
cdnMech

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