ActiveCell Problem

S

smandula

I can indepently get Trace to work, and Copyrange to print one line at a
time.
However, I can not both to work in conjunction with each other.

wht happens, is the a1..b1 rows, pause for 3 sec and then goes down one row
to a2..b2, pauses for two seconds, and then copies to e1..f1.
Here is the problem.
I now want to copy from e1..f1 to e5..f5 and loop until there is a blank
line
in column A,B
---------------------------------------------------
Public NextTime As Date
Sub Trace()
Sheet1.Range("A1").Select
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 3
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
Call LoopOn
End Sub

Sub LoopOn()
ActiveCell.Offset(1, 0).Select
Range("E1").Value = ActiveCell.Value
ActiveCell.Offset(0, 1).Select
Range("F1").Value = ActiveCell.Value
Call FindNum
NextTime = Now + TimeValue("00:00:02")
Application.OnTime NextTime, "LoopOn"
If Range("E1").Value = "" Then
Call LoopOff
End If
End Sub

Sub FindNum()
Range("A1").Activate
Do Until ActiveCell.Value = " "
If ActiveCell.Value = Range("E1").Value Then
Exit Sub
End If
ActiveCell.Offset(1, 0).Activate
Loop
'Call CopyRange2
End Sub

Sub LoopOff()
Application.OnTime NextTime, "LoopOn", , False
End Sub

Sub CopyRange2()
Sheets("sheet1").Range("E5:F5").Select
'find your empty cell
Do Until ActiveCell.Formula = ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Formula = Range("E1:F1").Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=
_
False, Transpose:=False
Application.CutCopyMode = True

End Sub
 
D

Dave Peterson

I'm kind of confused at what you're doing.

But this line (in copyrange2) looks like it's an error:

ActiveCell.Formula = Range("E1:F1").Copy

If the copy is successful, you'll get a True in the activecell.

But my real problem is I don't understand what you really want. Can you post
back with a description of what should happen? I think you'll get a better
answer, then.

And is there a reason you want to use .ontime and .wait's? Most people want the
macro to run as quickly as possible--with no delays.
 
S

smandula

Thank's for replying back!
I'm kind of confused at what you're doing.

What I am trying to do in the long run is to build a stock ticker simulator.
On the same worksheet, the data columns, are cols A and B with
row 1 (A1)Time and (B1) Current Price, these are both titles, with the
following
data starts at row 2:
Time Current Price
11:30 4.50
11:35 4.75
11:40 5.00
etc.
This feeds at two second intervals to E1 and F1 which at as monitors
for the simulated live feed that is coming from columns Aand B.
Eventually I will place Cols. A and B on a separate Date sheet, hidden
from view.
Cell E5 and F5, echo E1 and F1 (the monitor cells).
This is were I can not get the active cell to go from Cols A,B to E1,F1 to
E5,F5
and then back to ColsA,B next available row. It all stops on a blank row.
This it in a nut shell.
From here I can chart, or run stats against the made simulated feed data.

But this line (in copyrange2) looks like it's an error:

ActiveCell.Formula = Range("E1:F1").Copy

If the copy is successful, you'll get a True in the activecell.
Your are right, but, run Trace by itself and Copyrange2 by itself ,
to see the results individually.

It is getting the two Macro to run together which is my problem.
But my real problem is I don't understand what you really want. Can you post
back with a description of what should happen? I think you'll get a better
answer, then.

I hope I have explained things a bit better.
And is there a reason you want to use .ontime and .wait's? Most people want the
macro to run as quickly as possible--with no delays.

To simulate a sped up real time.

Thanks for looking at the program.
 
D

Dave Peterson

I'm still confused.

And I find activating cells in multiple routines even more confusing. Maybe
just keeping track of where one "activecell" should be and where the other
"activecell" should be:

Option Explicit

Public NextTime As Date
Dim CurCell As Range
Dim destCell As Range

Sub Trace()
Dim waitTime As Date
Dim newHour As Long
Dim newMinute As Long
Dim newSecond As Long

Set CurCell = Sheet1.Range("a1") 'start in A1
Set destCell = Sheet1.Range("e5") 'start pasting in E5:F5

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 3
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
Call LoopOn
End Sub
Sub LoopOn()

Set CurCell = CurCell.Offset(1, 0)
Range("E1").Value = CurCell.Value
Range("F1").Value = CurCell.Offset(0, 1).Value

Call CopyRange2

NextTime = Now + TimeValue("00:00:02")
Application.OnTime NextTime, "LoopOn"

If Trim(CurCell.Value) = "" Then
Call LoopOff
End If

End Sub

Sub LoopOff()
Application.OnTime NextTime, "LoopOn", , False
End Sub

Sub CopyRange2()
destCell.Resize(1, 2).Value = Sheet1.Range("e1:f1").Value
Set destCell = destCell.Offset(1, 0)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top