PC Review


Reply
Thread Tools Rate Thread

build a list with timestamps

 
 
steve0725@gmail.com
Guest
Posts: n/a
 
      22nd Dec 2008
Hi,

On one worksheet (Sheet1) I have a named range ("SumDaily") which is
pulling data from an outside source that updates automatically. I
would like to capture this data once every minute, paste as values
(transposed) on Sheet3 with a time stamp. I want to append it each
time to the bottom of the list so that at the end of a 6.5 hour period
I have 390 rows of data with respective timestamps (Row 1 has headers,
Column A would be time stamp).

Below is a recorded version of how I would do it for one line, but I
don't know how to append it to the bottom of a list, nor do I know how
to make it run automatically every 60 seconds (relative beginner with
VBA). I'm using Excel 2007, Windows XP.

Sub Macro1()

'Ideally I don't want it to activate the workbook since I want to be
working in other applications or other workbooks while it runs

Windows("MyWorkbook.xlsx").Activate
Sheets("Sheet1").Select
Application.Goto Reference:="SumDaily"
Selection.Copy
Sheets("Sheet3").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=True
Range("A2").Select
ActiveCell.FormulaR1C1 = "=NOW()"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub

A bonus would be to make it run only during market hours (9:30 AM -
4:00 PM), but this isn't necessary since I can just open and close the
workbook at those times.

Many thanks!
Steve
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      23rd Dec 2008
Sub GetData()

'Ideally I don't want it to activate the workbook since I want to be
'working in other applications or other workbooks while it runs

MyTime = Time

If MyTime >= TimeValue("6:30AM") And _
MyTime <= TimeValue("4:00PM") Then

With ThisWorkbook
Range("SumDaily").Copy
'Application.CutCopyMode = False
With .Sheets("Sheet3")
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
NewRow = LastRow + 1
.Range("B" & NewRow).PasteSpecial _
Paste:=xlPasteValues, _
Transpose:=True
.Range("A" & NewRow) = MyTime
End With
End With
End If
Application.OnTime Now + TimeValue("00:01:00"), "GetData"

End Sub





"(E-Mail Removed)" wrote:

> Hi,
>
> On one worksheet (Sheet1) I have a named range ("SumDaily") which is
> pulling data from an outside source that updates automatically. I
> would like to capture this data once every minute, paste as values
> (transposed) on Sheet3 with a time stamp. I want to append it each
> time to the bottom of the list so that at the end of a 6.5 hour period
> I have 390 rows of data with respective timestamps (Row 1 has headers,
> Column A would be time stamp).
>
> Below is a recorded version of how I would do it for one line, but I
> don't know how to append it to the bottom of a list, nor do I know how
> to make it run automatically every 60 seconds (relative beginner with
> VBA). I'm using Excel 2007, Windows XP.
>
> Sub Macro1()
>
> 'Ideally I don't want it to activate the workbook since I want to be
> working in other applications or other workbooks while it runs
>
> Windows("MyWorkbook.xlsx").Activate
> Sheets("Sheet1").Select
> Application.Goto Reference:="SumDaily"
> Selection.Copy
> Sheets("Sheet3").Select
> Range("B2").Select
> Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks _
> :=False, Transpose:=True
> Range("A2").Select
> ActiveCell.FormulaR1C1 = "=NOW()"
> Selection.Copy
> Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks _
> :=False, Transpose:=False
> Application.CutCopyMode = False
> End Sub
>
> A bonus would be to make it run only during market hours (9:30 AM -
> 4:00 PM), but this isn't necessary since I can just open and close the
> workbook at those times.
>
> Many thanks!
> Steve
>

 
Reply With Quote
 
steve0725@gmail.com
Guest
Posts: n/a
 
      23rd Dec 2008
Works great!!! Thanks.

One question...the time stamp includes a date (1/0/1900), depending on
how I format it. Is there a way to include today's date with the
time?

Thank you
Steve
 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      23rd Dec 2008
I made 3 changes

1) Added Date to MyTime when saving data to worksheet
.Range("A" & NewRow) = MyTime + Date

Date is the midnight time and Mytime is only the hours, minutes and seconds.

2) Changed Start time to 9:30. For testing I was using 6:30 and forgot to
change the time before posting
3) I changed the end time to <4:01PM so the 4:00PM time gets posted.
Otherwise the last posting would be 3:59PM.


Note:
You can add a workbook open event to automactically start the macro. Put
this code in the Thisworkbook VBA sheet.

Private Sub Workbook_Open()
Call GetData
End Sub



Sub GetData()

'Ideally I don't want it to activate the workbook since I want to be
'working in other applications or other workbooks while it runs


If MyTime >= TimeValue("9:30AM") And _
MyTime < TimeValue("4:01PM") Then

With ThisWorkbook
Range("SumDaily").Copy
'Application.CutCopyMode = False
With .Sheets("Sheet3")
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
NewRow = LastRow + 1
.Range("B" & NewRow).PasteSpecial _
Paste:=xlPasteValues, _
Transpose:=True
.Range("A" & NewRow) = MyTime + Date
End With
End With
End If
Application.OnTime Now + TimeValue("00:01:00"), "GetData"

End Sub

"(E-Mail Removed)" wrote:

> Works great!!! Thanks.
>
> One question...the time stamp includes a date (1/0/1900), depending on
> how I format it. Is there a way to include today's date with the
> time?
>
> Thank you
> Steve
>

 
Reply With Quote
 
steve0725@gmail.com
Guest
Posts: n/a
 
      23rd Dec 2008
Thanks, Joel. Appreciate the changes. One question...if I'm working
in another workbook while this is running in the background, it gives
me an error. I assume it's because of the "ThisWorkbook" code. Any
thoughts on how to get around this?

Thanks
Steve
 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      24th Dec 2008
I got an e-mail this afternoon indicating there was a new posting, yet when I
looked there is no message.

"Joel" wrote:

> I made 3 changes
>
> 1) Added Date to MyTime when saving data to worksheet
> .Range("A" & NewRow) = MyTime + Date
>
> Date is the midnight time and Mytime is only the hours, minutes and seconds.
>
> 2) Changed Start time to 9:30. For testing I was using 6:30 and forgot to
> change the time before posting
> 3) I changed the end time to <4:01PM so the 4:00PM time gets posted.
> Otherwise the last posting would be 3:59PM.
>
>
> Note:
> You can add a workbook open event to automactically start the macro. Put
> this code in the Thisworkbook VBA sheet.
>
> Private Sub Workbook_Open()
> Call GetData
> End Sub
>
>
>
> Sub GetData()
>
> 'Ideally I don't want it to activate the workbook since I want to be
> 'working in other applications or other workbooks while it runs
>
>
> If MyTime >= TimeValue("9:30AM") And _
> MyTime < TimeValue("4:01PM") Then
>
> With ThisWorkbook
> Range("SumDaily").Copy
> 'Application.CutCopyMode = False
> With .Sheets("Sheet3")
> LastRow = .Range("A" & Rows.Count).End(xlUp).Row
> NewRow = LastRow + 1
> .Range("B" & NewRow).PasteSpecial _
> Paste:=xlPasteValues, _
> Transpose:=True
> .Range("A" & NewRow) = MyTime + Date
> End With
> End With
> End If
> Application.OnTime Now + TimeValue("00:01:00"), "GetData"
>
> End Sub
>
> "(E-Mail Removed)" wrote:
>
> > Works great!!! Thanks.
> >
> > One question...the time stamp includes a date (1/0/1900), depending on
> > how I format it. Is there a way to include today's date with the
> > time?
> >
> > Thank you
> > Steve
> >

 
Reply With Quote
 
steve0725@gmail.com
Guest
Posts: n/a
 
      24th Dec 2008
On Dec 23, 3:26*pm, steve0...@gmail.com wrote:
> Thanks, Joel. *Appreciate the changes. *One question...if I'm working
> in another workbook while this is running in the background, it gives
> me an error. *I assume it's because of the "ThisWorkbook" code. *Any
> thoughts on how to get around this?
>
> Thanks
> Steve


See above. I get an error if I'm working in another workbook.
Thanks
Steve
 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      29th Dec 2008
This website has been down since the evening of the 23rd. Just came back up
this morning.

You can always set the workbook by using a variable like

from
with thisworkbook

to
Set Bk = activeworkbook
with BK

or specifically calling out the workbook name

Set Bk = workbooks("book1.xls")
with BK


"(E-Mail Removed)" wrote:

> On Dec 23, 3:26 pm, steve0...@gmail.com wrote:
> > Thanks, Joel. Appreciate the changes. One question...if I'm working
> > in another workbook while this is running in the background, it gives
> > me an error. I assume it's because of the "ThisWorkbook" code. Any
> > thoughts on how to get around this?
> >
> > Thanks
> > Steve

>
> See above. I get an error if I'm working in another workbook.
> Thanks
> Steve
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Build AutoComplete List (Outlook.nk2) from Contact List. genojoe Microsoft Outlook Contacts 4 3rd May 2008 03:42 AM
build list for eMail =?Utf-8?B?TmljayBY?= Microsoft Access VBA Modules 1 16th Oct 2006 07:26 PM
The Next Build Shall be RTM guys not any other builds unless MS decides to do one more build because of bugs before RTM RC2 build 5477 is the last build before RTM Drew Windows Vista General Discussion 8 13th Oct 2006 12:41 AM
I meant RC2 Build 5744 is the last build unless ms find more bugs before the RTM build and gold version there only make another build if there more bugs and not ready for RTM Drew Windows Vista General Discussion 4 12th Oct 2006 02:17 PM
build a list object from a comma-delimited list giant food Microsoft VB .NET 1 30th Mar 2004 05:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:24 PM.