Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 643
  • Last Modified:

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

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
Bob Berryman
Asked:
Bob Berryman
1 Solution
 
andymacfCommented:
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
 
Richard DanekeAdjunct FacultyCommented:
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
 
sstampfCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Bob BerrymanAuthor Commented:
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
 
Bob BerrymanAuthor Commented:
Update Values
0
 
Bob BerrymanAuthor Commented:
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
 
Bob BerrymanAuthor Commented:
Nevermind, I figured it out.

Thanks for all replies anyway.
0
 
Bob BerrymanAuthor Commented:
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
 
Bob BerrymanAuthor Commented:
This worked better for my needs.  Not what I was actually asking for I know.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now