我有一张Excel Sheet,它使用VBA宏在同一张纸上运行多个单元计时器。我正在使用3个按钮:启动,停止和重置以运行宏,并且定时器在我使用时工作正常。但是当我尝试共享此工作表时,我的“停止”和“重置”按钮变为非活动状态,尽管“开始”按钮工作正常。我是计算机上的一个完整的新手,我花了很多时间试图让我的计时器表工作只落到最后一个障碍。任何关于如何通过这个的建议将不胜感激。工作表上的代码如下:
enter code here
Dim maxrows As Long
Dim row, cols As Integer
Sub eventer()
Call addtime
Application.OnTime Now + TimeValue("00:00:01"), "Sheet1.eventer"
End Sub
Sub jukebox()
MsgBox "Face the music"
End Sub
Blockquote:增加按下开始按钮的每个单元格的时间。
Sub addtime()
maxrows = Sheet6.UsedRange.Rows.Count
For i = 2 To maxrows
row = Sheet6.Cells(i, 1).Value
cols = Sheet6.Cells(i, 2).Value
Sheet1.Cells(row, cols).Value = Sheet1.Cells(row, cols).Value
+TimeValue("00:00:01")
Next
End Sub
Blockquote创建一个列表(在另一个工作表上),该列表存储在其上运行计时器的每个单元格的位置(即每个单元上按下了“开始”按钮并且尚未应用“停止”按钮)。
Sub list()
Dim newss As Long
maxrows = Sheet6.UsedRange.Rows.Count
newss = maxrows + 1
Sheet6.Cells(newss, 1).Value = row
Sheet6.Cells(newss, 2).Value = cols
End Sub
Blockquote删除按下“停止”按钮的任何单元格位置 清单。
Sub listdel()
maxrows = Sheet6.UsedRange.Rows.Count
For i = 1 To maxrows
If Sheet6.Cells(i, 1).Value = row And Sheet6.Cells(i, 2).Value=cols
Then
Sheet6.Cells(i, 1).Delete shift:=xlUp
Sheet6.Cells(i, 2).Delete shift:=xlUp
Exit For
End If
Next
End Sub
Sub StartBtn_Click()
Selection.Interior.ColorIndex = 6
row = ActiveCell.row
cols = ActiveCell.Column
Selection.NumberFormat = "[h]:mm:ss;@"
ActiveCell.FormulaR1C1 = "12:00:00 AM"
Call list
End Sub
Sub Stop_Click()
Selection.Interior.ColorIndex = 4
row = ActiveCell.row
cols = ActiveCell.Column
Call listdel
End Sub
Sub Reset_Click()
Selection.Interior.ColorIndex = -4142
Selection.Value = "00:00:00"
Call listdel
End Sub
工作簿上的代码如下:
enter code here
Private Sub Workbook_Open()
Application.OnTime Now + TimeValue("00:00:01"), "Sheet1.eventer"
Sheets(1).Activate
Application.OnTime Now + TimeValue("00:00:01"), "Sheet2.eventer"
Sheets(2).Activate
End Sub