+ Reply to Thread
Results 1 to 12 of 12

Auto update all dates in a column to todays date on workbook open

  1. #1
    Registered User
    Join Date
    10-25-2016
    Location
    Birmingham
    MS-Off Ver
    2013
    Posts
    7

    Auto update all dates in a column to todays date on workbook open

    Hi Guys,

    I'm a complete noob when it comes to VBA programming in excel and was wondering if someone could help me with a problem I'm having.

    I have a task/issue tracking sheet that I use to manage my day to day workload. The sheet has a task due date column. Sometimes for whatever reason some dates pass before the item is complete and I would like it if these past dates auto updated (on workbook open) to todays date.

    I've given it a go but have failed so far.

    Can anyone help?

    Cheers

    Sam

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Auto update all dates in a column to todays date on workbook open

    Place this macro in the code module for ThisWorkbook:
    Please Login or Register  to view this content.
    Change the "A" in the code to match the column in your sheet that contains the dates you want changed. Save the file as a macro-enabled file so that its extension changes to "xlsm". Close the file and re-open it.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Auto update all dates in a column to todays date on workbook open

    The code above however will change ALL dates in the column to today not just the ones that have passed!

    Use this to determine the past ones
    Please Login or Register  to view this content.
    As mumps said, you'll need to change references, add in a reference to the relevant sheet etc
    If someone has helped you then please add to their Reputation

  4. #4
    Registered User
    Join Date
    10-25-2016
    Location
    Birmingham
    MS-Off Ver
    2013
    Posts
    7

    Re: Auto update all dates in a column to todays date on workbook open

    Hi, thanks for your help.

    Unfortunately it didn't work. Is it because I placed the code in the module for a sheet within the workbook not in "ThisWorkbook"? I should have said but I don't want the code to affect the entire workbook, just the issue/task tracking sheet within this workbook.

    Cheers

    Sam

  5. #5
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Auto update all dates in a column to todays date on workbook open

    Reference the range and sheet you want to use
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-25-2016
    Location
    Birmingham
    MS-Off Ver
    2013
    Posts
    7

    Re: Auto update all dates in a column to todays date on workbook open

    Just tried your suggestion pjwhitfield.

    Capture.PNG

    Not sure why the third line down has a problem??

  7. #7
    Registered User
    Join Date
    10-25-2016
    Location
    Birmingham
    MS-Off Ver
    2013
    Posts
    7

    Re: Auto update all dates in a column to todays date on workbook open

    Quote Originally Posted by pjwhitfield View Post
    Reference the range and sheet you want to use
    Please Login or Register  to view this content.
    Placed this code in "ThisWorkbook". Changed "sheet1" and "A:A" to the the right sheet and column. Saved, closed and reopened the workbook. This error message appeared "Run-time error '9': Subscript out of range".

    any idea?

  8. #8
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Auto update all dates in a column to todays date on workbook open

    Post your version of the code please

  9. #9
    Registered User
    Join Date
    10-25-2016
    Location
    Birmingham
    MS-Off Ver
    2013
    Posts
    7
    Quote Originally Posted by pjwhitfield View Post
    Post your version of the code please
    Private Sub Workbook_Open()
    Dim rng As Range
    Set rng = Worksheets("Sheet10").Range("B:B")
    For Each cell In rng
    If ((cell.Value < Date) And (IsDate(cell.Value))) Then
    cell.Value = Date
    End If
    Next cell
    End Sub

  10. #10
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Auto update all dates in a column to todays date on workbook open

    If I paste that into a new workbook and create a sheet10 with some data in column B it works fine.

    The only code in there which would cause a Subscript out of range error is the setting of the range which at first glance looks fine.

    Check your name of Sheet10, make sure it hasnt somehow got a space in it or something else. Try renaming that sheet (unless theres other code in your workbook that depends on it) and then changing the reference in this code to see if that makes a difference.

  11. #11
    Registered User
    Join Date
    10-25-2016
    Location
    Birmingham
    MS-Off Ver
    2013
    Posts
    7

    Re: Auto update all dates in a column to todays date on workbook open

    Quote Originally Posted by pjwhitfield View Post
    If I paste that into a new workbook and create a sheet10 with some data in column B it works fine.

    The only code in there which would cause a Subscript out of range error is the setting of the range which at first glance looks fine.

    Check your name of Sheet10, make sure it hasnt somehow got a space in it or something else. Try renaming that sheet (unless theres other code in your workbook that depends on it) and then changing the reference in this code to see if that makes a difference.
    Yep, you were right. The sheet reference was wrong. It works now!

    I've tried adding to the code as I would like it if only the cells on "open" tasks update with the current date. Immediately to the left of each dated cell there is a cell containing either "Open" or "Closed". So the dated cell (column B) should only update if the Open/Closed cell (column A) contains "Open". Here is my attempt at the code:

    Private Sub Workbook_Open()
    Dim rng As Range
    Set rng = Worksheets("Task and Issue Tracking").Range("B:B")
    For Each cell In rng
    If ((cell.Value < Date) And (IsDate(cell.Value))) And (ActiveCell.Offset(-1, 0).Value = "Open") Then
    cell.Value = Date
    End If
    Next cell
    End Sub

    Unfortunately this doesn't work. Any suggestions on what I'm doing wrong would be great!

    Cheers, Sam

  12. #12
    Registered User
    Join Date
    10-25-2016
    Location
    Birmingham
    MS-Off Ver
    2013
    Posts
    7

    Re: Auto update all dates in a column to todays date on workbook open

    Quote Originally Posted by smorri25 View Post
    Yep, you were right. The sheet reference was wrong. It works now!

    I've tried adding to the code as I would like it if only the cells on "open" tasks update with the current date. Immediately to the left of each dated cell there is a cell containing either "Open" or "Closed". So the dated cell (column B) should only update if the Open/Closed cell (column A) contains "Open". Here is my attempt at the code:

    Private Sub Workbook_Open()
    Dim rng As Range
    Set rng = Worksheets("Task and Issue Tracking").Range("B:B")
    For Each cell In rng
    If ((cell.Value < Date) And (IsDate(cell.Value))) And (ActiveCell.Offset(-1, 0).Value = "Open") Then
    cell.Value = Date
    End If
    Next cell
    End Sub

    Unfortunately this doesn't work. Any suggestions on what I'm doing wrong would be great!

    Cheers, Sam
    Any suggestions guys?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Automate todays date upon open workbook
    By TimlmiT in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-18-2013, 08:46 AM
  2. Auto Fill Todays Date In Column K in Last Value Found in Column A
    By trevor2524 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-18-2013, 02:42 PM
  3. [SOLVED] Open workbook on todays date
    By jshaw82 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-28-2013, 06:32 PM
  4. Replies: 2
    Last Post: 08-03-2012, 05:28 PM
  5. Cell Value = Todays date on workbook open
    By adam2308 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-08-2010, 05:03 PM
  6. Insert/append todays date when workbook is open
    By evenings in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-29-2010, 10:00 AM
  7. Auto open/close and update shared workbook
    By Nord in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-11-2009, 03:34 AM
  8. [SOLVED] Check column of dates against todays date
    By Andrew82 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-15-2005, 07:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1