Solved

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

Posted on 2011-02-17
9
617 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 18

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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now