Flashing Text In Excel

In Microsoft Word, it's ridiculously simple. Select Format | Font from the menu, click the Text Effects tab, and choose Blinking Background. You might expect similar help from Excel, but there's nothing remotely similar. Blinking text in Excel won't happen unless you make it happen with a little macro programming.

Suppose you want cell A1 to blink. Select Tools | Macro | Visual Basic Editor from the menu. Right-click the VBAProject item in the tree at left and choose Insert | Module from the pop-up menu. Now type and paste this text into the module:

Public NextFlash As Double Public Const FR As String = "Sheet1!A1" Sub StartFlashing() If Range(FR).Interior.ColorIndex = 3 Then Range(FR).Interior.ColorIndex = xlColorIndexNone Else Range(FR).Interior.ColorIndex = 3 End If NextFlash = Now + TimeSerial(0, 0, 1) Application.OnTime NextFlash, "StartFlashing", , True End Sub Sub StopFlashing() Range(FR).Interior.ColorIndex = xlColorIndexNone Application.OnTime NextFlash, "StartFlashing", , False End Sub

Arrange the VBA window and the Excel window so you can see cell A1 in Sheet1, then click within the StartFlashing macro, and press F5 to run it. The cell flashes! Click within StopFlashing and press F5 to stop the flashing.

How does it work? First, the constant FR defines the range that will flash; you can make different cells flash by changing its value. If the flash range has a red background, this macro sets it back to normal; if not, it makes the background red. Then it sets itself up to be called again in one second using the application's OnTime method.

The TimeSerial VBA function returns a numeric time-value corresponding to the number of hours, minutes, and seconds passed to it as input. TimeSerial takes only whole numbers, so the shortest time period it can calculate is the one second we use here. We set the NextFlash variable to the current time plus one second, and we call the application object's OnTime method to launch StartFlashing again at that time. Each call to the macro toggles the background from red

And it should also start flashing automatically when the workbook is opened. you can apply it to any range you like by changing the value of the FR constant. double-click the ThisWorkbook module and enter or Copy/Paste this text: Private Sub Workbook_Close() StopFlashing End Sub Private Sub Workbook_Open() StartFlashing End Sub Finally choose Close and Return to Microsoft Excel from the VBA Editor' File menu. and then save the workbook. The StopFlashing macro simply restores the normal background and calls OnTime to cancel the pending event. In the tree at left of the VBA Editor. so we'll add an automatic macro to take care of that. . And of course.to normal or vice versa. which is why we had to store that time in the public variable available to both macros. you have to pass the exact same time that was used to schedule it. To cancel an event. It's important to cancel all pending events when the workbook is closed. That's a lot of work just to get flashing text. but it does the job.

2001 5:39 AM I am tracking the amount of money being spent on cell phone charges for managers in my company. i would like to have the text.00.00. blink in cell H21 if the value is equal to or greater than $1000.00 worth of charges each quarter. Is this possible? Thanks.Archive of Mr Excel Message Board Back to Excel VBA archive index Back to archive home If cell H21 >$1000. On my spreadsheet. Each person is allowed up to $1000. blink text?? Posted by Tony on December 14. Check out our Excel VBA Resources Answer-Re: If cell H21 >$1000. . blink text?? Posted by Dan on December 14. 2001 6:41 AM I modified some code that I found on jwalk.00.com written by Bill Manville (give credit where credit is due) and that I think this will suit your needs.

8). schedule:=False Cells(21.ColorIndex = 2 End With Application. "Flash" Application. else black. Let me know if you need more help.OnTime NextTime.OnTime NextTime.00.Font If . thanks it worked great!!! Now.Value > 1000 Then Flash Else StopIt End If End Sub This should make your cell flash red if over 1000. HTH. 2001 7:42 AM Dan.First. Dan. "Flash". it didn't work.OnTime NextTime.ColorIndex = 2 Then .Range) Calculate If Cells(21. 8).00. blink text?? Posted by Tony on December 14. ByVal Target As Excel. 8). One more question: If cell H21 >$1000. blink text?? .Font.ColorIndex = 3 Else . "Flash" End Sub Sub StopIt() Application. copy the following and paste in a Module on your workbook: Dim NextTime As Date Sub Flash() NextTime = Now + TimeValue("00:00:01") With Cells(21. I forgot to tell you: If cell H21 >$1000.ColorIndex = xlAutomatic End Sub Next: Copy and paste this code in to the "This Workbook" project sheet: Private Sub Workbook_SheetChange(ByVal Sh As Object. how do i edit the code to also flash if Cell c22 exceeds another number such as 6? I tried changing the 1000 to a 6 but.

Here's my way around it. 2001 8:35 PM Unfortunately it's not that easy. the flashing works. I'm taking off here shortly. Is there a way to use the spinner numbers? Re: I forgot to tell you: If cell H21 >$1000. Dan. When the spinner number reaches 1000. I'm assuming you know how to do that since you put it there in the first place. **remove the cell link from your spin button**. if i use my KB to input 1000 in H21. But. 2001 7:52 AM Dan. use SpinButton1_Change (in the sheet module). Re: I forgot to tell you: If cell H21 >$1000. blink text?? Posted by Dan on December 14. nothing happens. :) Then paste the following code in the "This Workbook" code sheet: Private Sub Workbook_BeforeClose(Cancel As Boolean) StopItH21 End Sub Private Sub Workbook_Open() If Range("H21") > 1000 Then FlashH21 Else StopItH21 End Sub .. You can email me (darag2358@yahoo. let me know. let me think about it this weekend and get back to you. Final Answer? Posted by Dan on December 14. It errors out when trying to constantly change the font of a cell that is linked to a spin button. 2001 9:20 AM Hmm.Posted by Tony on December 14. Doesn't seem to want to work using the spin button.00.00.com) with your e-mail address and I'll get back in touch. (1)i am using a spinner to show the values in H21 and H22. 2001 3:50 PM Instead of the Workbook_SheetChange procedure. I'm dealing only with cell H21 here and made the code a little more readable. If you need help in adding the other cell. First. blink text?? Posted by Thersites on December 14.

. you have my email address.1 'Decrements value of cell by 1 If Range("H21") > 1000 Then FlashH21 Else StopItH21 End Sub Private Sub SpinButton1_SpinUp() Range("H21") = Range("H21") + 1 'Increments value of cell by 1 If Range("H21") > 1000 Then FlashH21 Else StopItH21 End Sub Finally.ColorIndex = 2 Then .OnTime NextTime.. schedule:=False Range("H21"). "FlashH21".OnTime NextTime.Font.. "FlashH21" Application. Let me know if there are any other problems..ColorIndex = 2 End With Application...Font If . insert a module and place this code there: Dim NextTime As Date Sub FlashH21() NextTime = Now + TimeValue("00:00:02") With Range("H21"). The flashing seems a little quirky (of course I didn't write that part :)) but I can't think of a better way to do that. A further final answer ! . .OnTime NextTime.Then paste the following in the worksheet code that your spin button is on (I am assuming that the spinner for H21 is called SpinButton1: Private Sub SpinButton1_SpinDown() Range("H21") = Range("H21") ... "FlashH21" End Sub Sub StopItH21() Application..ColorIndex = xlAutomatic End Sub I tested it and it seems to work....ColorIndex = 3 Else ...

8).Value > 6 Then Flash End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) StopIt End Sub . If you need help in adding the other cell. 8). It errors out when trying to constantly change the font of a cell that is linked to a spin button.Font If . let me know. "Flash". 2001 10:59 PM Unfortunately it's not that easy.Font. 8). I couldn't produce any error. I'm dealing only with cell H21 here and made the code a little more readable.OnTime NextTime. "Flash" Application.OnTime NextTime.ColorIndex = 2 End With Application. schedule:=False You said "It errors out when trying to constantly change the font of a cell that is linked to a spin button".OnTime NextTime.ColorIndex = xlAutomatic End Sub Private Sub SpinButton1_Change() StopIt If Cells(21. I'm assuming you know how to do that since you put it there in the first place.Value > 6 Then Flash End Sub Private Sub Workbook_Open() If Cells(21. "Flash" End Sub Sub StopIt() Application. :) Then paste the following code in the "This Workbook" code sheet: Private Sub Workbook_BeforeClose(Cancel As Boolean) . schedule:=False Cells(21. 8). Here's my way around it. **remove the cell link from your spin button**. First. The following works for me :Dim NextTime As Date Sub Flash() NextTime = Now + TimeValue("00:00:01") With Cells(21.Posted by Thersites on December 14.ColorIndex = 2 Then .ColorIndex = 3 Else .

.Thanks for the help guy's!! Posted by Tony on December 17.MrExcel. Inc. MrExcel is a registered trademark of Tickling Keys.com. All contents © 1998-2004 MrExcel.com. 2001 6:17 AM This archive is from the original message board at www. Microsoft Excel is a registered trademark of the Microsoft Corporation. Visit our online store to buy searchable CD's with thousands of VBA and Excel answers.

Sign up to vote on this title
UsefulNot useful