+ Reply to Thread
Results 1 to 6 of 6

Vba to subtract current date from date in column G and put static diff in column H

  1. #1
    Registered User
    Join Date
    05-31-2013
    Location
    Fort Wayne, IN, USA
    MS-Off Ver
    Excel 2010
    Posts
    7

    Vba to subtract current date from date in column G and put static diff in column H

    I have searched through many threads and many websites and can't find the pieces to accomplish this task.

    I have a date in column G of my worksheet and I want to subtract the current date from it and put the difference (either positive or negative) in column H.

    I want this to be done when the workbook is opened but once the calculation has populated column H it should never update it. In other words, if I open the workbook and column H is populated and I subsequently save and close the workbook, the next time I open it the calculation will leave the already existing values in column H alone.

    This is a document metric workbook stored in a restricted location so no one else can save it back to that location. It is dynamically updated with current dates that documents are, or will be, due for review. Column H will be negative if the doc is already overdue, or positive if it is not yet due. Since we grab a "current" update once a week, we want to be able to store it in another location and not have the metric in column H change when we open the workbook at a later date.

  2. #2
    Forum Contributor
    Join Date
    05-29-2013
    Location
    MD
    MS-Off Ver
    Excel 365
    Posts
    148

    Re: Vba to subtract current date from date in column G and put static diff in column H

    You can modify the ThisWorkbook_Open event in VBA to add some code to check whether the cells are populated and if not perform the calculation.

    Thanks
    Duncan

  3. #3
    Registered User
    Join Date
    05-31-2013
    Location
    Fort Wayne, IN, USA
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Vba to subtract current date from date in column G and put static diff in column H

    Thanks, that helps with one of my issues. The one I've spent all day on is the math to get the number for column H.

  4. #4
    Forum Contributor
    Join Date
    05-29-2013
    Location
    MD
    MS-Off Ver
    Excel 365
    Posts
    148

    Re: Vba to subtract current date from date in column G and put static diff in column H

    Try:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-31-2013
    Location
    Fort Wayne, IN, USA
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Vba to subtract current date from date in column G and put static diff in column H

    I'm guessing you meant "Worksheets" rather than "Sheets". Regardless, I get a "Type mismatch error" with this...
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    05-29-2013
    Location
    MD
    MS-Off Ver
    Excel 365
    Posts
    148

    Re: Vba to subtract current date from date in column G and put static diff in column H

    You can use Sheets("Sheet1").Range too

    Try this:

    Please Login or Register  to view this content.
    This will test to see if the cell is empty first, then apply the formula in the cell.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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