Follow the code with improvements:
The rules are simple, in the code where this: vStrLocalsProibidos = "A3,A5" Voce must declare all places where Voce wishes not to have permission. Interspersed with comma (,)
Example.
I want to block Columns A, C, D, E, G up to Z and also block rows 3 and 5 and cell B2. Thus Voce has a lot of flexibility to make any combination.
vStrLocalsProibidos = "A:A,C:D,E:E,G:Z,3:3,5:5,B2"
suggestion. not to have to type this down. Select all areas you want to block with the mouse and CTRL pressed. And then immediately you use
?Selection.address
to take the 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
Worked perfectly!!!
– Carlos PvP