You are here:

Excel/Create new rows for every fixed time interval

Advertisement


Question
QUESTION: Hi

Hope you are able to help.

On sheet1, A1, A2, A3, to A8 have data. These data are constantly changing. These data come from external data acquisition.

On Sheet2, at an interval of say 1 minute, to capture the data in Sheet1 A1 to A8 and put into Sheet2 A1 to A8 together with a date and time stamp. In the next minute, to put the data into B1 to B8, and in the 3nd minute, to put the data into C1 to C8 and so on. So after 2 hours, there should be 120 rows of data, enough to monitor the change of data over a 2-hour duration.

Help need to create all the formula for sheet2?
Thank You
Puah

ANSWER: This works...


Public n As Integer
Sub Auto_Open()
   Application.OnTime Now + 1/1440, "post" 'one minute
End Sub
Sub post()
   Sheets(1).Range("A1:A8").Copy
   Sheets(2).Range("A1").Offset(0, n).PasteSpecial
   n = n + 1
   Application.CutCopyMode = False
   if n<120 then Auto_Open
End Sub

---------- FOLLOW-UP ----------

QUESTION: Thank Bob for your prompt response. I'm not familiar with programming and how to put this code into excel. Can you point to me which I can learn this online. Thank again.

ANSWER: Copy all I gave you as an answer, then press Alt/F11, then Insert/Module, then Paste.
To get back to excel, press Alt/Q.
If this is currently a file with an xlsx extension it will need to be changed to xlsm (xls is fine).
The file needs to be saved.
Next time you open the file it will all happen automatically.

---------- FOLLOW-UP ----------

QUESTION: It works!

However, I have the cells orientation mixed up and named the wrong cells. The question should read as follows:
On sheet1, A1, B1, C1, D1, E1, F1, G1, H1 have data. These data are constantly changing. These data come from external data acquisition.

On Sheet2, at an interval of say 1 minute, to capture the data in Sheet1 A1 to H1 and put into Sheet2 A1 to H1 together with a date and time stamp. In the next minute, to put the data into A2 to H2, and in the 3rd minute, to put the data into A3 to H3 and so on. So after 2 hours, there should be 120 rows of data, enough to monitor the change of data over a 2-hour duration.

Also how to add a date and time (computer time) to each row so that we know when a particular row of data is captured.

Answer
Public n As Integer
Sub Auto_Open()
   Application.OnTime Now + 1/1440, "post" 'one minute
End Sub
Sub post()
   Sheets(1).Range("A1:H1").Copy
   Sheets(2).Range("A1").Offset(n).PasteSpecial
   Sheets(2).Range("I1").offset(n).value = Now
   Sheets(2).Columns.Autofit
   n = n + 1
   Application.CutCopyMode = False
   if n<120 then Auto_Open
End Sub
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Bob Umlas

Expertise

I`m a Microsoft Excel MVP (Most Valuable Professional) and have been since the inception of the program in 1995. I can answer every kind of Excel question except: API, Importing/exporting to other programs (powerpoint, word,...) Also check out my in-person training link at http://www.thumbtack.com/ny/new-york/excel-training/

Experience

Worked with MS Excel since version 0.99 (on the Mac!). Was contributing editor to Excellence Magazine, having written >300 articles. John Walkenbach said of me "I finally met someone who knows as much about Excel as I do."

Publications
Excellence, The Expert, Microsoft

Education/Credentials
BA in math, Hofstra University, 1965

Awards and Honors
MVP
Led sessions for the Convergence 2004-2006 seminar on Excel tips & tricks

©2016 About.com. All rights reserved.