问题
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.
- Open up your workbook
- Get into VB Editor (Press Alt+F11)
- Insert a new module (Insert > Module)
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 SubGet out of VBA (Press Alt+Q)
- Save your sheet
- Click on the Control Toolbox Command Button icon
- Draw a button on your worksheet
- Right-click the button and select Properties
- Change the Caption to Start Timer
- Right-click the button and select View Code
Paste in this code for the command button:
Private Sub CommandButton1_Click() Call StartTimer End SubSwitch back to your spreadsheet
Repeat steps 7-12 to create a Stop Timer button
Private Sub CommandButton2_Click() Call StopTimer End SubPress Alt-Q to close the VBEditor and save your sheet
Try the buttons :)
来源:https://stackoverflow.com/questions/33118467/log-vaule-in-excel-cell