Check whether you have created two macros named StopNow. There should be only one.
Also: make sure that you haven't named the module StopNow. That would confuse VBA.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have VBA code to make Column F to blink
VBA Code
When I click on command button Color 3 and I click OK and run the command button again
Color 8
Color 10
Color 5
Color 0
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Check whether you have created two macros named StopNow. There should be only one.
Also: make sure that you haven't named the module StopNow. That would confuse VBA.
CommandButton1 is the name of a command button, it is not a macro. Hence the error message.
Copy the following code into it, and change Sheet1 to the name of the worksheet for which you want to toggle the color.
Dim d As Date
Sub ChangeColor()
Static i As Long
i = (i + 1) Mod 5
ThisWorkbook.Worksheets("Sheet1").Range("F2:F300").Interior.ColorIndex = _
Choose(i + 1, 3, 8, 10, 5, 0)
d = DateAdd("s", 3, Now)
Application.OnTime d, "ChangeColor"
End Sub
Sub StopNow()
On Error Resume Next
Application.OnTime d, "ChangeColor", , False
End Sub
Private Sub CommandButton1_Click()
ChangeColor
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
StopNow
End Sub
Your event is CommandButton1_Click. You don't have a sub named CommandButton1. But we can fix that:
Insert the code below between the lines
Private Sub CommandButton1_Click()
and
Dim d As Date
CommandButton1
End Sub
Sub CommandButton1()
So that your code ends up looking like this:
Private Sub CommandButton1_Click()
CommandButton1
End Sub
Sub CommandButton1()
Dim d As Date
......
End Sub
Then everything should work fine