循环记录“ X”个指标的时间

问题描述

我要记录600种不同的股票,不同的买入/卖出评级,并且我要运行此宏并平均记录每只股票需要多少秒。这很好并且有效,但是现在我想看看一组20只股票需要多长时间。我希望能够记录20只股票的数量,记录每只股票花费多长时间。我需要这个宏来遍历所有600只股票,同时记录记录20只股票需要多长时间。如何获得该宏以告诉我运行600次中的20次需要多长时间?我想将时间值从“ C30”开始,然后将每个下一个值向下偏移1个单元格

'
' Repeat Macro
'
'
Start = Timer

  Dim i As Integer
  
For i = 1 To 600

  Call Sheet4.SpinButton1_SpinDown
  DoEvents
  Application.Run "EikonRefreshWorkbook"
  DoEvents
  Application.Run "EikonRefreshWorkbook"
  DoEvents
  Call copyPaste
  DoEvents

Next i

elapsedtime = Format((Timer - Start) / (86400 * 600),"hh: mm: ss: ms ")
Range("C30").End(xlDown).Offset(1,0).Value = elapsedtime


    MsgBox "Indicators have been updated.",vbOKOnly

End Sub

解决方法

这应该做您想要的。我建议添加工作表引用Cells

我将除数设置为变量,因此如果您修改了值,您就不会忘记在偏移量计算中更改值。

    Dim i As Long
    Dim start As Long
    Dim groupval as long
    groupval = 20 'Change this to change the group size
    start = Timer
    For i = 1 To 600

        Call Sheet4.SpinButton1_SpinDown
        DoEvents
        Application.Run "EikonRefreshWorkbook"
        DoEvents
        Application.Run "EikonRefreshWorkbook"
        DoEvents
        Call CopyPaste
        DoEvents
  
        If i Mod groupval = 0 Then
            Cells(30,3).Offset((i / groupval) - 1).Value = Format((Timer - start) / (86400 * 600),"hh: mm: ss: ms ")
            start = Timer
        End If
  
    Next i

    MsgBox "Indicators have been updated.",vbOKOnly


End Sub