一切工作正常,最多64行,而不是停止传输数据。
Option Explicit
Public dTime As Date
;Main program
Sub ValueStore ()
Dim dTime As Date
Range("B" & Cells(Rows.Count).Row).End(xlUp).Offset(1, 0).Value = Range("A1").Value
Range("c" & Cells(Rows.Count).Row).End(xlUp).Offset(1, 0).Value = Range("A2").Value
Range("D" & Cells(Rows.Count).Row).End(xlUp).Offset(1, 0).Value = Range("A3").Value
Range("E" & Cells(Rows.Count).Row).End(xlUp).Offset(1, 0).Value = Range("A4").Value
Range("F" & Cells(Rows.Count).Row).End(xlUp).Offset(1, 0).Value = Range("A5").Value
Call StartTimer
End Sub
开始的第一个按钮
Sub StartTimer()
dTime = Now + TimeValue("00:00:05") !here i tack 5 sec
Application.OnTime dTime, "ValueStore", Schedule:=True
End Sub
停止的第二个按钮
Sub StopTimer()
On Error Resume Next
Application.OnTime dTime, "ValueStore", Schedule:=False
End Sub
答案 0 :(得分:0)
Cells(Rows.Count).Row
为64。这是因为Rows.Count
将是1048576,因此Cells(1048576)
指的是第64行的单元格XFD64
。您的代码需要指定一列,以便它查看1048576中的单元格一栏。
Option Explicit
Public dTime As Date
;Main program
Sub ValueStore ()
Dim dTime As Date
Dim nextRow As Long
'Calculate the row number once
nextRow = Cells(Rows.Count, "B").End(xlUp).Row + 1
Range("B" & nextRow).Value = Range("A1").Value
Range("c" & nextRow).Value = Range("A2").Value
Range("D" & nextRow).Value = Range("A3").Value
Range("E" & nextRow).Value = Range("A4").Value
Range("F" & nextRow).Value = Range("A5").Value
Call StartTimer
End Sub