restrict data entry to specific areas in the sheet

robertvdb

Active Member
Joined
Jan 10, 2021
Messages
334
Office Version
  1. 2016
Platform
  1. Windows
I have this sheet where I want to restrict data entry to the three blocks A B C.

The code below works fine for block A. But I want to expand this code to blocks B and C, in the same Sub.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Integer
 
i = Target.Row

If i >= 1 And i <= 10 Then
    If Target.Column >= 1 And Target.Column <= 4 Then
        Exit Sub
    Else
        Application.EnableEvents = False
        Cells(i, 1).Select  'col A
        Application.EnableEvents = True
        Exit Sub
    End If
   
   
    'here I want similar code for blocks B and C
   
End If

End Sub
 

Attachments

  • sunday.png
    sunday.png
    18.5 KB · Views: 9

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    Application.EnableEvents = False
    If Target.Row <= 10 Then
        Select Case Target.Column
            Case Is = 5, 6
                Range("A" & Target.Row).Select
            Case Is = 11, 12
                Range("G" & Target.Row).Select
            Case Is > 16
                Range("M" & Target.Row).Select
        End Select
    End If
    Application.EnableEvents = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

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