log vaule in excel cell

故事扮演 提交于 2019-12-25 03:12:51

问题


I have a large excel file with scripts running to collect data from various locations. One of the cells in the sheet generates a two digit number every 10th minute. I would like to collect this number in this specific cell every 10th minute and log the value in a different sheet or a log (doesn't matter which format) Right now we can just read the value as it is displayed, but we keep a log to trace the ups and downs.


回答1:


Please see edited answer

When you open the sheet you hit the start timer button, then when you want it to stop press the stop timer.. this will copy the value from E15 to Sheet 2 A1 and below every 1 hour 1 second.

Taken and edited from here

Please make sure you make a copy and try it on that first.

  1. Open up your workbook
  2. Get into VB Editor (Press Alt+F11)
  3. Insert a new module (Insert > Module)
  4. Copy and Paste in your code

    Option Explicit
    Public dTime As Date
    
    Sub ValueStore()
    Dim dTime As Date
    Worksheets("Sheet2").Range("a" & Cells(Rows.Count).Row).End(xlUp).Offset(1, 0).Value = Range("E15").Value
    Call StartTimer
    End Sub
    
    
    Sub StartTimer()
    dTime = Now + TimeValue("01:00:01")
    Application.OnTime dTime, "ValueStore", Schedule:=True
    End Sub
    
    Sub StopTimer()
    On Error Resume Next
    Application.OnTime dTime, "ValueStore", Schedule:=False
    End Sub
    
  5. Get out of VBA (Press Alt+Q)

  6. Save your sheet
  7. Click on the Control Toolbox Command Button icon
  8. Draw a button on your worksheet
  9. Right-click the button and select Properties
  10. Change the Caption to Start Timer
  11. Right-click the button and select View Code
  12. Paste in this code for the command button:

    Private Sub CommandButton1_Click()
    Call StartTimer
    End Sub
    
  13. Switch back to your spreadsheet

  14. Repeat steps 7-12 to create a Stop Timer button

    Private Sub CommandButton2_Click()
    Call StopTimer
    End Sub
    
  15. Press Alt-Q to close the VBEditor and save your sheet

Try the buttons :)



来源:https://stackoverflow.com/questions/33118467/log-vaule-in-excel-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!