Tuesday 19 June 2018

vba - Implementing 3 different Macros on Multiple Cells in a Sheet by Selection

I am a complete noob at both excel and Vba and am trying to come up with code that can give me a timer and a cell color change that occurs when I click on my three buttons StartBtn, StopBtn and ResetBtn. Right now I got the code to work for a single cell B3 but need the buttons to work for any cell on the sheet that is clicked on. I am pasting the code below and hope you guys would be kind enough to go through the code and save this confused noob.


Code:


Dim StopTimer           As Boolean
Dim SchdTime As Date
Dim Etime As Date
Const OneSec As Date = 1 / 86400#

Private Sub StartBtn_Click()
Range("B3").Interior.ColorIndex = 6
StopTimer = False
SchdTime = Now()
[B3].Value = Format(Etime, "hh:mm:ss")
Application.OnTime SchdTime + OneSec, "Sheet1.NextTick"
End Sub

Private Sub ResetBtn_Click()
Range("B3").Interior.ColorIndex = -4142

StopTimer = True
Etime = 0
[B3].Value = "00:00:00"
End Sub


Private Sub StopBtn_Click()
Range("B3").Interior.ColorIndex = 4
StopTimer = True
Beep
End Sub

Sub NextTick()
If StopTimer Then
'Don't reschedule update
Else
[B3].Value = Format(Etime, "hh:mm:ss")
SchdTime = SchdTime + OneSec
Application.OnTime SchdTime, "Sheet1.NextTick"
Etime = Etime + OneSec
End If

End Sub

No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...