Hello,
I need help with combining these two codes into the Worksheet_Change sub, I can get them to work on their own but can't combine them properly.
In the first sub I am ensuring users enter a date in the date field when entering data in other columns in the row:
If Target.Cells.Count > 1 Then Exit Sub
Dim ans As String
Application.EnableEvents = False
ans = "Please enter a date for this activity."
If Target.Column = 3 And Target.Offset(, -1).Value = "" Then: MsgBox ans: Target.Value = "": Target.Offset(, -1).Select
If Target.Column = 4 And Target.Offset(, -1).Value = "" Then: MsgBox ans: Target.Value = "": Target.Offset(, -2).Select
If Target.Column = 5 And Target.Offset(, -1).Value = "" Then: MsgBox ans: Target.Value = "": Target.Offset(, -3).Select
Application.EnableEvents = True
End Sub
The second sub clears the value in column 6 if users make changes to column 5:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Column = 5 Then
If Target.Validation.Type = 3 Then
Application.EnableEvents = False
Target.Offset(0, 1).ClearContents
End If
End If
exitHandler:
Application.EnableEvents = True
Exit Sub
End Sub
Thanks!
I need help with combining these two codes into the Worksheet_Change sub, I can get them to work on their own but can't combine them properly.
In the first sub I am ensuring users enter a date in the date field when entering data in other columns in the row:
If Target.Cells.Count > 1 Then Exit Sub
Dim ans As String
Application.EnableEvents = False
ans = "Please enter a date for this activity."
If Target.Column = 3 And Target.Offset(, -1).Value = "" Then: MsgBox ans: Target.Value = "": Target.Offset(, -1).Select
If Target.Column = 4 And Target.Offset(, -1).Value = "" Then: MsgBox ans: Target.Value = "": Target.Offset(, -2).Select
If Target.Column = 5 And Target.Offset(, -1).Value = "" Then: MsgBox ans: Target.Value = "": Target.Offset(, -3).Select
Application.EnableEvents = True
End Sub
The second sub clears the value in column 6 if users make changes to column 5:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Column = 5 Then
If Target.Validation.Type = 3 Then
Application.EnableEvents = False
Target.Offset(0, 1).ClearContents
End If
End If
exitHandler:
Application.EnableEvents = True
Exit Sub
End Sub
Thanks!