View Single Post
 
Old 12-03-2019, 02:35 PM
NoSparks NoSparks is offline Windows 7 64bit Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 842
NoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of light
Default

Here's the code, commented line by line for better understanding.
Code:
Sub UpdateIntakeDate()
    Dim rng As Range    'the overall range to work on
    Dim cel As Range    'the one cell to work on at a time
    Dim lr As Long      'the last row with data in the column
    
With Sheets("Client Tracker")

'determine last used row in the column
    lr = .Cells(.Rows.Count, "E").End(xlUp).Row
'if lr is less than first row that would have dates don't go any further
    If lr < 6 Then Exit Sub    '<<<<<<<<<<<<<
    
'set the range to work on
    Set rng = .Range("E6:E" & lr)
    
'work on the cells in the range one at a time
    For Each cel In rng
        'if the cell IS NOT blank
        If cel <> "" Then
'check if today is greater than or equal to the date in the cell plus one year
            If Date >= DateAdd("yyyy", 1, cel) Then
               'if it is then give it the new date
               cel = DateSerial(Year(Date), Month(cel.Value), Day(cel.Value))
            End If
        End If
'move on to the next cel by going back to the start of For Each
    Next cel

End With

End Sub
Reply With Quote