Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-03-2019, 02:35 PM
NoSparks NoSparks is offline Automatically update user-inputted date after specified time range Windows 7 64bit Automatically update user-inputted date after specified time range 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
Reply

Tags
automatically, update, year



Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically update user-inputted date after specified time range Auto update excel graph range, ignore data when date reads 00-Month-00 SavGDK Excel 2 06-24-2016 08:05 AM
Automatically update user-inputted date after specified time range Auto populating dates on timesheet for week from one inputted date ohi Word VBA 3 12-04-2014 12:11 PM
Date/Time Formula for Entry level XL user talon1driver Excel 2 09-18-2014 02:32 PM
Mail merge with filter using data inputted by user Tornado70 Mail Merge 6 04-09-2013 07:16 AM
Automatically update user-inputted date after specified time range How to update automatically the “file name” as we do for the “Date”? Jamal NUMAN Word 2 01-06-2011 02:43 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:21 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft