Hi there,
I need help with this code that I have put together:
Private Sub worksheet_selectionchange(ByVal target As Range)
Static LastCell As Range
If Not LastCell Is Nothing Then
If LastCell.Column = 16 Then
If Not IsEmpty(LastCell.Offset(0, -1)) Then
If IsEmpty(LastCell) Then
MsgBox (" Cell cannot be blank.")
Application.EnableEvents = False
LastCell.Select
Application.EnableEvents = True
End If
End If
End If
End If
Set LastCell = ActiveCell
If Not LastCell Is Nothing Then
If LastCell.Column = 15 Then
If Not IsEmpty(LastCell.Offset(0, 1)) Then
If IsEmpty(LastCell) Then
MsgBox (" Cell cannot be blank")
Application.EnableEvents = False
LastCell.Select
Application.EnableEvents = True
End If
End If
End If
End If
Set LastCell = ActiveCell
End Sub
What I am trying to achieve is a pop-up if a cell in column O is blank but the cell in column P is not blank and vice versa.
It works when cell in column O is not blank and you try to leave cell in column P blank but it let's you leave cell in column O blank and populate cell in column P and go to the next row unless you go back to the cell in column O afterwards!
Or if you know of a better way to code this, please let me know.
Thanks.
I need help with this code that I have put together:
Private Sub worksheet_selectionchange(ByVal target As Range)
Static LastCell As Range
If Not LastCell Is Nothing Then
If LastCell.Column = 16 Then
If Not IsEmpty(LastCell.Offset(0, -1)) Then
If IsEmpty(LastCell) Then
MsgBox (" Cell cannot be blank.")
Application.EnableEvents = False
LastCell.Select
Application.EnableEvents = True
End If
End If
End If
End If
Set LastCell = ActiveCell
If Not LastCell Is Nothing Then
If LastCell.Column = 15 Then
If Not IsEmpty(LastCell.Offset(0, 1)) Then
If IsEmpty(LastCell) Then
MsgBox (" Cell cannot be blank")
Application.EnableEvents = False
LastCell.Select
Application.EnableEvents = True
End If
End If
End If
End If
Set LastCell = ActiveCell
End Sub
What I am trying to achieve is a pop-up if a cell in column O is blank but the cell in column P is not blank and vice versa.
It works when cell in column O is not blank and you try to leave cell in column P blank but it let's you leave cell in column O blank and populate cell in column P and go to the next row unless you go back to the cell in column O afterwards!
Or if you know of a better way to code this, please let me know.
Thanks.