Solved

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

Posted on 2011-02-17
9
616 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

743 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

10 Experts available now in Live!

Get 1:1 Help Now