How to record/save data @ a specific time?

Cusuma

Board Regular
Joined
Dec 2, 2004
Messages
91
Hi,

I have some stock prices in a sheet I want to save to another sheet (in the same workbook) each day at 4 pm. How do I write a macro that does that?

Say I have stock prices for company, A, B and C in Column A1, B1 and C1. Each day @ 4 pm I want these prices to be saved to a sheet so I have a database with historic prices. This is what I want the macro to do.

Many thanks
Cusuma
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

gardnertoo

Well-known Member
Joined
Jul 24, 2007
Messages
938
First macro: the archive macro.

I've made the assumptions that your data is on worksheet Sheet1 and your archive will live on Sheet2. On sheet 2, enter the company names in cells A1, B1, and C1. In a Module, insert the following code:
Code:
Sub archive()
    With Worksheets("Sheet2")
        nextrow = Cells(.Rows.Count, "A").End(xlUp).Row + 1
        .Cells(nextrow, 1).Resize(1, 3).Value = Sheets("Sheet1").Range("A1:C1").Value
        .Cells(nextrow, 4).Value = Date
        
    End With
End Sub
This will look for the first empty row below the headings and existing data, and fill in the current values in Sheet1 A1, B1, C1 to that row on Sheet2. It then puts the current date in column D of that row.


Second: scheduling the macro to run.

In the code window for This Workbook enter this code:
Code:
Private Sub workbook_open()
Application.OnTime "4:00 pm", "archive"
End Sub

I've further assumed that you close this workbook at night, and re-open it in the morning. If that's true, every morning when you open it, the macro named archive() will be schduled to run at 4:00pm. If you don't close and re-open the workbook, the next 4:00 pm acrchive cycle will NOT run.
 
Upvote 0

Forum statistics

Threads
1,190,783
Messages
5,982,895
Members
439,805
Latest member
IDarkstarX

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top