Follow the code with improvements:
The rules are simple, in the code where it is: vStrLocaisProibidos="A3, A5" you must declare all the places where you wish to not have permission. Interleaved by comma (,)
Example.
I want to block Columns A, C, D, E, G onwards until Z, and I also want to block lines 3 and 5 and cell B2. That way you have a lot of flexibility to do any combination.
vStrLocationsProhibited="A: A, C: D, E: E, G: Z, 3: 3.5: 5, B2"
Suggestion. so you do not have to type it that down. Select all the areas that you want to block with the mouse and the CTRL pressed. And then immediately you use
? selection.address
to get addresses without suffering. : D
Dim vErrLineMove As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim vStrLocaisProibidos As String
Dim vRngReturn As Variant
Dim vMaxError As Long
'definido para parar depois que a macro tenta colocar um novo local
'depois de 10 tentativas. Ele para e mantem o cursor a onde for.
vMaxError = 10
vStrLocaisProibidos = "A:A,C:D,E:E,G:Z,3:3,5:5,B2"
If vStrLocaisProibidos = vbNullString Then Exit Sub
Set vRngReturn = Application.Intersect(Target.Worksheet.Range(vStrLocaisProibidos), Target)
If Not vRngReturn Is Nothing Then
Beep
If vErrLineMove < vMaxError Then
vErrLineMove = vErrLineMove + 1
Cells(Target.Row, Target.Column).Offset(0, 1).Select
End If
End If
vErrLineMove = 0
End Sub
att.
Hudson Komuro