[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Excel -- Macro to Save XLS # of times

Posted on 2013-12-12
3
Medium Priority
?
269 Views
Last Modified: 2013-12-12
Experts:

In Excel, I've have a graph with a data series linked to a RANDBETWEEN function (cell range).

As designed, each time I click, e.g., the "Save" icon, the random function regenerates its value set and therefore the graph is updated.    This works great.

I now would like to add the following elements to the spreadsheet.
1. Have a cell (e.g., A1) that contains a drop-down box (values of, e.g., 10, 20, 30, etc.)
2. Add a command button that calls a macro
3. Macro's purpose is to save the Excel spreadsheet n time of times (as specified in the drop-down menu).  So, if cell value in A1=10, then clicking on the macro will save/re-save the XLS 10 times.    Therefore, the linked graph gives the appearance of being animated.

The execution of the save should be driven by a time factor.   For example, based on another cell value, I want the save/re-save to occur every second or every two seconds.   (Otherwise, if the Excel would execute in mili-seconds, it probably would defeat the purpose.)

I'm flexible to other suggestions... as long as the envisioned process allows to specify, e.g, the refresh of the random function to occur every # of seconds.

Any recommendations how to achieve this?

EEH
0
Comment
Question by:ExpExchHelp
  • 2
3 Comments
 
LVL 11

Expert Comment

by:Angelp1ay
ID: 39714244
You can just call recalculate instead of save. Probably a bit healthier for your computer.

Recalculate can be called manually by hitting:
F9

Open in new window


The VBA call is:
Application.Calculate

Open in new window

0
 
LVL 11

Accepted Solution

by:
Angelp1ay earned 2000 total points
ID: 39714260
This seems to run fairly well :)
Sub MyMacro()
    Dim i, loops As Integer
    loops = ActiveSheet.Range("A1")
    
    Dim t As Date
    t = Now()
    
    For i = 0 To loops
        t = DateAdd("s", 1, t)
        Application.Wait (t)
        Application.Calculate
    Next
End Sub

Open in new window


For bonus points, set the number of seconds to pause in B1 :)
Sub MyMacro()
    Dim i, loops, interval As Integer
    loops = ActiveSheet.Range("A1")
    interval = ActiveSheet.Range("B1")
    
    Dim t As Date
    t = Now()
    
    For i = 0 To loops
        t = DateAdd("s", interval, t)
        Application.Wait (t)
        Application.Calculate
    Next
End Sub

Open in new window

0
 

Author Closing Comment

by:ExpExchHelp
ID: 39714355
That worked for me!   Thanks.

EEH
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

872 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