I would like VBA to copy A1.B1 values to A2.B2 at 8:00am, then copy A1.B1 values to A3.B3 at 8:15am and so on until 4 pm. I don't know how to do VBA, but I'm trying to learn it. Thank you.
Hi Bill, welcome to the boards.
Ok, this may not be the best way of doing things, but seeing as nobody else has replied this may well be your best shot for the time being.
Right, so this method involves 2 macros and a workbook_open event. Let's start with the workbook_open event first:
- Go to the VBA developer window, locate your document in the project window on the left, then right-click on ThisWorkbook and select View Code.
- Paste in the following code
Rich (BB code):
Private Sub Workbook_Open()
' At set time runs "Copy_A1B1" macro
Application.OnTime TimeValue("08:00"), "Copy_A1B1"
End Sub
Next we will deal with the 2 macros.
- Go to the VBA developer window, locate your document in the project window on the left, then right-click on ThisWorkbook and select Import>Module
- Paste in the following 2 macros
Rich (BB code):
Sub Copy_A1B1()
' Sets screen updating to false to prevent screen flicker
Application.ScreenUpdating = False
' Select Sheet1 cells A1 and B1 and copy
Worksheets("Sheet1").Range("A1:B1").Copy
' Find the next empty row based on column A
Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1).Select
' Paste the copied data
ActiveSheet.Paste
' Call the "TimerReset" macro
Call TimerReset
' Save the workbook
ActiveWorkbook.Save
End Sub
Rich (BB code):
Sub TimerReset()
' Instructs Excel to run "Copy_A1B1" macro again in 15 minutes
Application.OnTime Now + TimeValue("00:15:00"), "Copy_A1B1"
End Sub
So what does the above actually do?
The workbook open event tells Excel that at 08:00 it needs to run the "Copy_A1B1" macro.
The "Copy_A1B1" macro copies cells A1 and B1 to the next free row, then calls the "TimerReset" macro.
The "TimerReset" macro tells Excel to run "Copy_A1B1" again in 15 minutes.
This process then obviously loops every 15 minutes.
I hope this helps or at least gets you going in the right direction.