Solved

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

Posted on 2011-02-17
9
621 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

710 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