I have a data in column A update every minute. I h

2019-09-16 05:12发布

Everything working fine up to 64 rows than it stop transferring data.

 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

First button for start

Sub StartTimer()
    dTime = Now + TimeValue("00:00:05") !here i tack 5 sec
    Application.OnTime dTime, "ValueStore", Schedule:=True
End Sub

Second button for stop

Sub StopTimer()
    On Error Resume Next
    Application.OnTime dTime, "ValueStore", Schedule:=False
End Sub

1条回答
The star\"
2楼-- · 2019-09-16 05:48

Cells(Rows.Count).Row is 64 in modern versions of Excel files. That is because Rows.Count will be 1048576, and therefore Cells(1048576) is referring to cell XFD64 which is on row 64. Your code needed to specify a column so that it looked at the 1048576th cell in one column.

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
查看更多
登录 后发表回答