Blog Archive
About Me
Seguidores
Estatisticas
204: VBA: - Evento WorkSheet_Change, Método Intersect
Vejamos o exemplo:
Na folha1:
Private Sub Worksheet_Change(ByVal Target As Range)
'JRod - Microsoft [MVP] - Excel
'blog: http://EXCELer.blogspot.com
'site: http://www.exceler.org
'email1: mail@exceler.org
'email2: blog.exceler@netcabo.pt
'
Const WS_RANGE As String = "A2:A10"
Dim c As Range, myRange As Range
On Error GoTo ws_exit
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Set myRange = Sheets(1).Range("A2:A10")
For Each c In myRange
If c.Value = ActiveCell.Offset(-1, 0).Value Then
If c.Offset(0, 1).Value = "S" Then
MsgBox "O trabalhador encontra-se de Baixa." & Chr(10) & "Inserção Impossível!", Buttons:=vbInformation
ActiveCell.Offset(-1, 0).Activate
ActiveCell.Value = ""
End If
End If
Next
End With
End If
ws_exit:
Application.EnableEvents = True
End Sub
Tópicos relacionados: