Hi,
I had a Worksheet_Change(ByVal Target As Range) event, then I needed to add another event to the same worksheet, which I did. Then I read that it is a good practice to have an Application.EnableEvents = False and Application.EnableEvents = True statements in the code but I wasn't sure where exactly to put those, so I was experimenting and..... my both events stopped working even when I deleted "Application.EnableEvents =" statements and returned to have just the first event.
I would highly appreciate if you could help to correct and improve the code.
Private Sub Worksheet_Change(ByVal Target As Range)
' Unhide spouse column based on filing type.
Dim pctRng As Range
If Target.Address = ("$B$1") Then
If Target.Text = "T1" Then
Columns("C").EntireColumn.Hidden = True
ElseIf Target.Text = "T2" Then
Columns("C").EntireColumn.Hidden = False
ElseIf Target.Text = "T3" Then
Columns("C").EntireColumn.Hidden = False
ElseIf Target.Text = "T4" Then
Columns("C").EntireColumn.Hidden = True
ElseIf Target.Text = "T5" Then
Columns("C").EntireColumn.Hidden = True
End If
End If
' Enter range to watch for new entries in
Set pctRng = Range("B4:B12")
' Exit if updated cell not in watched range
If Not Intersect(Target, pctRng) Is Nothing Then
End If
' Check for each condition
If Range("Age_1") <= 30 Then
If Range("$B$18") > 10000 Then
MsgBox "You have entered ...............", _
vbRetryCancel + vbCritical, "WARNING"
End If
Else
If Range("$B$18") > 12000 Then
MsgBox "You have entered ............", _
vbRetryCancel + vbCritical, "WARNING"
End If
End If
End If
End Sub
When the code works, I also need to add cell "$C$18" to the below part of the code. So if you could please incorporate it into your solution, that would be great.
If Range("$B$18") > 10000 Then
MsgBox "You have entered ...............", _
vbRetryCancel + vbCritical, "WARNING"
End If
Else
If Range("$B$18") > 12000 Then
MsgBox "You have entered ............", _
vbRetryCancel + vbCritical, "WARNING"
End If
P.S. this is related to this post with updated cell addresses.
I had a Worksheet_Change(ByVal Target As Range) event, then I needed to add another event to the same worksheet, which I did. Then I read that it is a good practice to have an Application.EnableEvents = False and Application.EnableEvents = True statements in the code but I wasn't sure where exactly to put those, so I was experimenting and..... my both events stopped working even when I deleted "Application.EnableEvents =" statements and returned to have just the first event.
I would highly appreciate if you could help to correct and improve the code.
Private Sub Worksheet_Change(ByVal Target As Range)
' Unhide spouse column based on filing type.
Dim pctRng As Range
If Target.Address = ("$B$1") Then
If Target.Text = "T1" Then
Columns("C").EntireColumn.Hidden = True
ElseIf Target.Text = "T2" Then
Columns("C").EntireColumn.Hidden = False
ElseIf Target.Text = "T3" Then
Columns("C").EntireColumn.Hidden = False
ElseIf Target.Text = "T4" Then
Columns("C").EntireColumn.Hidden = True
ElseIf Target.Text = "T5" Then
Columns("C").EntireColumn.Hidden = True
End If
End If
' Enter range to watch for new entries in
Set pctRng = Range("B4:B12")
' Exit if updated cell not in watched range
If Not Intersect(Target, pctRng) Is Nothing Then
End If
' Check for each condition
If Range("Age_1") <= 30 Then
If Range("$B$18") > 10000 Then
MsgBox "You have entered ...............", _
vbRetryCancel + vbCritical, "WARNING"
End If
Else
If Range("$B$18") > 12000 Then
MsgBox "You have entered ............", _
vbRetryCancel + vbCritical, "WARNING"
End If
End If
End If
End Sub
When the code works, I also need to add cell "$C$18" to the below part of the code. So if you could please incorporate it into your solution, that would be great.
If Range("$B$18") > 10000 Then
MsgBox "You have entered ...............", _
vbRetryCancel + vbCritical, "WARNING"
End If
Else
If Range("$B$18") > 12000 Then
MsgBox "You have entered ............", _
vbRetryCancel + vbCritical, "WARNING"
End If
P.S. this is related to this post with updated cell addresses.