Improve company productivity with a Business Account.Sign Up

x
?
Solved

MS Excel - Way to auto update values without closing and re-opening workbook?

Posted on 2011-02-17
9
Medium Priority
?
644 Views
Last Modified: 2012-05-11
I have an Excel 2007 workbook (XLS format) that uses VLOOKUP to populate data from another workbook on our network.  It works great, but the workbook from which it grabs data from is always changing.  So I always need to have the most up to date data.  Currently, I have to click Data>Edit Links>Update Values or close and re-open the workbook.

Is there a macro or something to tell Excel to automatically do an Update Values every X minutes?

Thanks,
0
Comment
Question by:Bob Berryman
9 Comments
 
LVL 7

Expert Comment

by:andymacf
ID: 34921521
You could record a macro that does this task and then just press Ctrl + ? (you assign the key)

or Press F9

Alternatively, I found this code.  Replace the column reference with your actual columns used in your sheet

right click the sheet tab > view code > paste in the below

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
ActiveSheet.UsedRange.Columns("A:C").Calculate
End Sub

You just have to double click anywhere within the active range and it will update.

Cheers
Andy
0
 
LVL 19

Expert Comment

by:Richard Daneke
ID: 34922261
The F9 is the standard keyboard for Calculate Now.
In 2007, the Formulas ribbon tab has a calculate ribbon group with a calculate now button.
When you right-click on any ribbon icon, you can add this to your Quick Access Toolbar.  Then, you can click once and recalculate an entire spreadsheet.
ExcelCalculateRibbonGroup.JPG
0
 
LVL 12

Expert Comment

by:sstampf
ID: 34925054
The below code might help. I haven't tested it though.

Copy and paste the entire code. I have inserted comments in the code for your reference.

Taken/Modified from: http://www.cpearson.com/
Public RunWhen As Double
Const cRunIntervalSeconds = 120 ' two minutes
Const cRunWhat = "TheSub"  ' the name of the procedure to run

'To start the auto-update process run this code once
Sub StartTimer()
    RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
    Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
        Schedule:=True
End Sub

Sub TheSub()
    ActiveSheet.Range("A1:C2000").Calculate 'set range as per your need
    StartTimer  ' Reschedule the procedure
End Sub


'To stop the auto-update process run this code
Sub StopTimer()
    On Error Resume Next
    Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
        Schedule:=False
End Sub

Open in new window

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:Bob Berryman
ID: 34929029
When I click Calculate Now nothing happens on my workbook.  But if I click Update Values it does.  So I'm not sure if the above solutions will work.
0
 
LVL 1

Author Comment

by:Bob Berryman
ID: 34929035
Update Values
0
 
LVL 1

Author Comment

by:Bob Berryman
ID: 34929611
I was able to record a macro and assign it a keyboard shortcut and a Quick Access Toolbar button.  The only thing is that this will be used by many people and I'm trying to automate the process as much as possible so they won't actually have to click anything.

Here is the code from my macro.  Any way to change it to tell it to run automatically every so many minutes?  Or even better would be to tell it to run when the user prints the workbook.
Sub Update_Timesheet()
'
' Update_Timesheet Macro
' Updates populated data in timesheet, which is pulled from the MPL.
'
' Keyboard Shortcut: Ctrl+u
'
    ActiveWorkbook.UpdateLink Name:= _
        "\\PCES_FILESERVER\PCES Job File Server\Master Project Log COPY\PCES Master Project Log COPY.xlsm" _
        , Type:=xlExcelLinks
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:Bob Berryman
ID: 34929686
Nevermind, I figured it out.

Thanks for all replies anyway.
0
 
LVL 1

Accepted Solution

by:
Bob Berryman earned 0 total points
ID: 34929707
Private Sub Workbook_BeforePrint(Cancel As Boolean)
'
' Update_Timesheet Macro
' Updates populated data in timesheet, which is pulled from the MPL.
'
' Keyboard Shortcut: Ctrl+u
'
    ActiveWorkbook.UpdateLink Name:= _
        "\\PCES_FILESERVER\PCES Job File Server\Master Project Log COPY\PCES Master Project Log COPY.xlsm" _
        , Type:=xlExcelLinks
End Sub

Open in new window


I put this in BeforePrint.  This will actually be a better solution for my needs.  I know it isn't what I asked for originally.  Sorry.
0
 
LVL 1

Author Closing Comment

by:Bob Berryman
ID: 34959208
This worked better for my needs.  Not what I was actually asking for I know.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article describes a serious pitfall that can happen when deleting shapes using VBA.
I tried to use the SharePoint app to Import a Spreadsheet and import an Excel sheet into a Team site made in SharePoint 2016. But that just resulted in getting an error message 'Unknown Error'...
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

606 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question