+ Reply to Thread
Results 1 to 5 of 5

VBA function not refreshing Excel 2016

  1. #1
    Registered User
    Join Date
    05-25-2018
    Location
    Bristol, England
    MS-Off Ver
    365
    Posts
    11

    VBA function not refreshing Excel 2016

    Morning all,

    Long time reader, first time poster, so hello!

    I'm having a bit of trouble getting a VBA function to refresh. I would like to have a cell at the top of my excel sheet which shows the last time the file was modified, I am using the following function:

    Please Login or Register  to view this content.
    However it will not refresh unless I click into the cell and press enter.

    Please can you help by suggesting how this might refresh without being clicked on?

    Thanks in advance,

    Max

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Give it a try !


    Better is to use a workbook event so paste next code to the ThisWorkbook module and mod the range to suit your need :

    PHP Code: 
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As BooleanCancel As Boolean)
        
    Range("A1").Value Now
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  3. #3
    Registered User
    Join Date
    05-25-2018
    Location
    Bristol, England
    MS-Off Ver
    365
    Posts
    11

    Re: VBA function not refreshing Excel 2016

    Hello,

    Thank you very much for your reply. Unfortunately I'm not sure how to do what you're suggesting. Was 'ThisWorkbook' supposed to be a hyperlink?

    This is the first time I'm using VB so might need some baby steps!

    Thanks again!

  4. #4
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,497

    Re: VBA function not refreshing Excel 2016

    Hi Maxwelln1

    Application.volatile "instructs" excel to also recalculate this function every time the sheet is recalulated.
    I think "the problem" is that a workbook is normally recalculated just before it is saved. But the property last save time is not updated yet because that property is set after/ during save process.
    you cloud verify this by saving your worksheet and then pressing F9 thought triggers a recalc and should also update your UDF (user defined function)

    The solution of Marc L would solve that problem as the cell A1 is updated just before (a split second) the workbook is saved.

  5. #5
    Registered User
    Join Date
    05-25-2018
    Location
    Bristol, England
    MS-Off Ver
    365
    Posts
    11

    Re: VBA function not refreshing Excel 2016

    Hi Roel,

    Thank you for your help. I can confirm that saving and then pressing F9 does update the cell to show the correct time/date.

    Oh I figured out what to do with Marc L's code and it worked perfectly! Thank you both for your help

    Just to help others (if as new to this as me), I pressed alt-F11, then on the VBA screen clicked Insert -> New Module and pasted this code in:

    Please Login or Register  to view this content.
    Then, in the Project - VBAProject window on the left there is a folder structure, I went into 'Microsoft Excel Objects' and found the module 'ThisWorkbook' and pasted in Marc L's code:

    Please Login or Register  to view this content.
    You can change A1 to be any cell of your choice where you want the date to appear. I went to cell A1 and typed in the following:

    Please Login or Register  to view this content.
    Then format the cell as date or time and you're off to the races! Saving the sheet updates the cells.

    Thank you again to both of you above!


    EDIT - I've just realised that you may not even need to do the first and last step at all!
    Last edited by maxwelln1; 05-25-2018 at 04:44 AM.

+ 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. Replies: 1
    Last Post: 09-18-2017, 08:27 AM
  2. Help! Automated Email coding for Excel 2016 and Outlook 2016 problems
    By lisa6421 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-01-2017, 08:07 AM
  3. Refresh All Button Not Refreshing Pivot Tables Excel 2016
    By hkfenmil in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 07-10-2017, 03:35 AM
  4. Replies: 1
    Last Post: 07-07-2017, 03:11 PM
  5. Excel 2016 - Pivot table not refreshing
    By Cubicle Convict in forum Excel General
    Replies: 1
    Last Post: 05-31-2017, 10:11 AM
  6. Ms Excel 2016 IF function
    By tryhyper in forum Excel General
    Replies: 9
    Last Post: 08-13-2016, 08:08 PM
  7. Excel Calc function not refreshing
    By paulusdu in forum Excel General
    Replies: 2
    Last Post: 02-13-2007, 11:57 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