Ironman
Well-known Member
- Joined
- Jan 31, 2004
- Messages
- 1,069
- Office Version
- 365
- Platform
- Windows
I've just been very kindly given the below code by Eric W relating to this post
I'd be grateful, if it's possible, for the above ranges to be changed automatically each year on Jan 1 by the number of days in the year (i.e. taking account of leap years)
e.g. On 1 Jan 2022 both ranges will change from C8413:C8777 and D8413:D8777 to C8778:C9142 and D8778:D9142
Many thanks!
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyData As Variant, OldMax As Double
If Not Intersect(Target, Range("C8413:C8777")) Is Nothing Then
MyData = Range("C8413:C8777").Value
MyData(Target.Row - 8413 + 1, 1) = ""
OldMax = WorksheetFunction.Max(MyData)
If Target.Value > OldMax Then MsgBox "Maximum distance achieved"
End If
If Not Intersect(Target, Range("D8413:D8777")) Is Nothing Then
MyData = Range("D8413:D8779").Value
MyData(Target.Row - 8413 + 1, 1) = ""
OldMax = WorksheetFunction.Max(MyData)
If Target.Value > OldMax Then MsgBox "Maximum time achieved"
End If
End Sub
I'd be grateful, if it's possible, for the above ranges to be changed automatically each year on Jan 1 by the number of days in the year (i.e. taking account of leap years)
e.g. On 1 Jan 2022 both ranges will change from C8413:C8777 and D8413:D8777 to C8778:C9142 and D8778:D9142
Many thanks!