I have a worksheet with a Worksheet_Change sub in it.
I have two sets of code in it.
Each set, individually, works as planned (tested). But when together, for some reason only the first set is catching correctly.
Here is the code:
I believe the issue of the 2nd set of code not catching the changes to B3 stems from the first set of code's 1st line:
As I understand it, if the changed cell is not B2, then the sub exits, thus the code for B3 never runs.
Is that right?
I see the issue (I believe), but I am not sure about how to solve it.
Any thoughts, ideas, pointers?
Maybe if I change the 1st line to something like:
And have the second set start like this:
I am just not sure if that is the best way to do it.
What would the best way to make the code simpler, better, more efficient, not as sloppy (hahaha), etc.
I don't think the use of GoTo is very efficient.
Ideas? Thoughts? Suggestions? Pointers?
-Spydey
As always, your assistance and patience is very very much appreciated!
I have two sets of code in it.
Each set, individually, works as planned (tested). But when together, for some reason only the first set is catching correctly.
Here is the code:
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
''Change worksheet name
If Target.Cells.Count > 1 Or Intersect(Target, Range("B2")) Is Nothing Then Exit Sub
Application.EnableEvents = False
If IsEmpty(Target.Value) Then
Application.ActiveSheet.Name = "Template"
Else
If IsNumeric(Target.Value) Then
Application.ActiveSheet.Name = Target
End If
End If
Application.EnableEvents = True
''Calculate number of days
If Target.Cells.Count > 1 Or Intersect(Target, Range("B3")) Is Nothing Then Exit Sub
Application.EnableEvents = False
If IsEmpty(Target.Value) Then
Target.Offset(2, 0).ClearContents
Else
If IsDate(Target.Value) Then
Target.Offset(2, 0) = Application.WorksheetFunction.Days360(Range("B3"), Date, False)
End If
End If
Application.EnableEvents = True
End Sub
I believe the issue of the 2nd set of code not catching the changes to B3 stems from the first set of code's 1st line:
Code:
If Target.Cells.Count > 1 Or Intersect(Target, Range("B2")) Is Nothing Then Exit Sub
As I understand it, if the changed cell is not B2, then the sub exits, thus the code for B3 never runs.
Is that right?
I see the issue (I believe), but I am not sure about how to solve it.
Any thoughts, ideas, pointers?
Maybe if I change the 1st line to something like:
Code:
If Target.Cells.Count > 1 Or Intersect(Target, Range("B2")) Is Nothing Then GoTo CalculateDays
And have the second set start like this:
Code:
''Calculate number of days
CalculateDays:
If Target.Cells.Count > 1 Or Intersect(Target, Range("B3")) Is Nothing Then Exit Sub
I am just not sure if that is the best way to do it.
What would the best way to make the code simpler, better, more efficient, not as sloppy (hahaha), etc.
I don't think the use of GoTo is very efficient.
Ideas? Thoughts? Suggestions? Pointers?
-Spydey
As always, your assistance and patience is very very much appreciated!
Last edited: