Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Can I set a Cell to Flash based on a particular DOW

0

I am trying to find a way to flash a particular cell if it is a Thursday.

This would serve as a visual reminder to do a task every Thursday.

I'm pretty sure there is no way to do this via a Macro, But, I am able to use VB code. Just need a way to reference the cell and flash it with a different color back and forth every 2 or 3 seconds.

Answer
Discuss

Discussion

Hello John and welcome to the forum,

Making a cell flash based on a particular condition is definitely possible. Macros and VB are essentially the same thing. Making a cell flash using VBA  means that doing something in the workbook is restricted until the macro finishes. Would it be OK to have the cell flash when the workbook is opened? After the workbook is opened how long should the cell flash? 10 seconds? 20 seconds?
Give us a bit more information and one of us should be able to help you. If possible, upload a sample file (without any personal info).

Cheers   :-)
WillieD24 (rep: 557) Oct 13, '23 at 2:21 am
Yeah, sorry, I should have said Macro Recorder. I was hoping to utilize a solution that would not tie up the workbook. I had not thought of that factor. Upon reflection, perhaps I should just utilize a Message Box in a BeforeSave Event?
JohnThro60 (rep: 4) Oct 13, '23 at 8:43 am
Hi John,

Another approach would be to have the message box pop-up when the file is opened or a specific cell(s) is changed. (Workbook_Open event or Worksheet_Change event).

Cheers   :-)
WillieD24 (rep: 557) Oct 13, '23 at 12:00 pm
Would'nt a message box in a Worksheet_Change event pop up a box every time you updated a cell?
JohnThro60 (rep: 4) Oct 13, '23 at 12:15 pm
Not necessarily. In the Worksheet_Change event you can specify which cell (Target) triggers the pop-up.

Another option, provided there is space available, is to have an unused cell provide the reminder. This would require an in-cell formula and conditional formatting. The in-cell formula would check to see if the current day is Thursday, if so enter the reminder message, if not leave it blank. The CF rule would add cell fill colour if the cell contains text. This method would cause the reminder to be visible all day Thursday without affecting the functionality of the sheet/workbook.

Cheers   :-)
WillieD24 (rep: 557) Oct 13, '23 at 12:22 pm
Could you show me a piece of code that would target a specific cell in a Worksheet_Change event? Thanks.
JohnThro60 (rep: 4) Oct 13, '23 at 12:26 pm
Hi John,
Here is a sample of how simple the code can be:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 
' when cell C3 is selected the message box pops-up
 
If Target.Address = "$C$3" Then
 
    MsgBox "Your reminder goes here."
 
End If
    
End Sub

Cheers   :-)
WillieD24 (rep: 557) Oct 13, '23 at 1:08 pm
Thank You for your knowlegable help.
JohnThro60 (rep: 4) Oct 13, '23 at 11:50 pm
You might be interested in the (more general) solution in my Answer. It does the requested flashing thing (but I agree that conditional formatting is the more normal approach).
John_Ru (rep: 6142) Oct 14, '23 at 8:38 am
@John - did you deselect my Answer by mistake or is there a problem with it? Please explain (under the Answer).

@Willie - you made some good points above. One minor thing, if a user already has a Reputation on the Forum, they are returning so there's no need to welcome them. By all means greet them politely, as usual.
John_Ru (rep: 6142) Oct 14, '23 at 12:44 pm
Add to Discussion

Answers

0
Selected Answer

Hi John,

I am posting my solution as an answer so you can select it.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' when cell C3 is selected the message box pops-up
If Target.Address = "$C$3" Then
    MsgBox "Your reminder goes here."
End If
End Sub

Here is a repeat of the other option I suggested.

Another option, provided there is space available say an empty row, is to have an unused cell provide the reminder. This would require an in-cell formula and conditional formatting. The in-cell formula would check to see if the current day is Thursday, if so enter the reminder message, if not leave it blank. The CF rule would add cell fill colour if the cell contains text. This method would cause the reminder to be visible all day Thursday without affecting the functionality of the sheet/workbook.

Cheers   :-)

Discuss

Discussion

Well done Willie. Arguably your solution didn't address the "flash" question but John seems pleased so "happy days"!
John_Ru (rep: 6142) Oct 15, '23 at 1:43 pm
@John_Ru
Thanks for the props. I am impressed with your solution in that, even if the sheet is "flashing", it is possible to do things on the sheet. Once again your superior knowledge has provided a solution which is a level up above mine and provided a teachable moment for me. Good job.
:-)
WillieD24 (rep: 557) Oct 16, '23 at 12:07 am
@Willie - thanks for your kind comments.

You're right- sheet can be editted while the "day" task rows flash but (with my setting of 7 flashes) only the quickest of tasks could be cleared during the flashes. They would however get their timestamp and cause the row to cease flashing.

I enjoyed piecing together the solution so it's a bonus if you and John learned anything new from it. 
John_Ru (rep: 6142) Oct 16, '23 at 3:15 am
Add to Discussion
0

Hi JohnThro60

In the attached spreadsheet, I've created a more general task list on Sheet1, with any repeat day currently in column B- feel free to change them. Any number of rows might be used.

When the file opened for the first time on a day, say a Saturday, all tasks due on that weekday will have N set in the Done column and the row will flash yellow every second (for a defined number of times) then become yellow. I've done that since constantly flashing would be just irritating in my opinion.

If it's opened again on the day, only those rows with N in the Done? column will flash. That's achieved using the worksheet Last Used (which could be hidden or VBA VeryHidden) which is used to record the date it was last opened. (You can manually  set it to a previous day to test the feature above). That's done when the file is opened, using this (commented) code:

Private Sub Workbook_Open()

    ' stop triggering other coes
    Application.EnableEvents = False
    ' if file first opened today, call procedure
    If Date > Sheet2.Cells(1, 2).Value Then Call DayDue

    ' record date of opening in hidden sheet
    Sheet2.Cells(1, 2) = Date

    Application.EnableEvents = True
    'initiate flashes
    Call Timer

End Sub

where the first bold lines set today's rows to yellow if needed. After that (and recording the date), the second bold ones call the timer routine (in Module 1).

Module 1 starts with some Public declarations (with hopefully meaningful names if you look at Sheet1): for constants (which you can alter) and variables (in bold for the Timer)

' define where the data is
Public Const DayClm As Long = 2, DoneClm As Long = 5, DataStartRw As Long = 4, DataLastClm As Long = 8, DoneTimeClm As Long = 6
' define variable for flash timer
Public Const MaxFlashes As Long = 7
Public Interval As Double, Flashes As Long

The code which clear tasks (and sets them to yellow) on first opening on a given day is this:

Sub DayDue()
    ' initiated on first workbook opening of the day

    Dim Rw As Long, LastDayRw As Long

    ' find last row containing a Repeat day
    LastDayRw = Sheet1.Cells(Rows.Count, DayClm).End(xlUp).Row
    ' loop down
    For Rw = DataStartRw To LastDayRw
        With Sheet1.Cells(Rw, 1)
            ' check if due today
            If .Offset(0, DayClm - 1).Value = Format(Date, "dddd") Then
                ' if so, colour row, set Done to N and clear completion columns
                .Resize(1, DataLastClm).Interior.Color = vbYellow
                .Offset(0, DoneClm - 1).Value = "N"
                .Offset(0, DoneClm).Resize(1, 3).Value = ""
            End If
        End With
    Next Rw

End Sub

The Workbook_Open code initiates the code which flashes the rows. This is based on one of Don's Tutorials (in that section) : Run a Macro at Set Intervals in Excel but I've counted the Flashes and stoppped them after the defined MaxFlashes (main changes in bold):

Sub Timer()

    If Flashes <= 2 * MaxFlashes - 1 Then
        ' add 1 second
        Interval = Now + TimeValue("00:00:01")
        'Tell Excel when to next run the macro.
        Application.OnTime Interval, "Flash"

        Else
        ' reset count for next open
        Flashes = 0
    End If

End Sub

Sub Flash()

    Dim Rw As Long, LastDayRw As Long

    ' find last row containing a Repeat day
    LastDayRw = Sheet1.Cells(Rows.Count, DayClm).End(xlUp).Row
    ' loop down
    For Rw = DataStartRw To LastDayRw
        With Sheet1.Cells(Rw, DoneClm)
            ' check if Done is N
            If .Value = "N" Then
                ' if so, toggle row colour
                If .Interior.Color = vbYellow Then
                    Sheet1.Cells(Rw, 1).Resize(1, DataLastClm).Interior.ColorIndex = xlNone
                    Else
                    Sheet1.Cells(Rw, 1).Resize(1, DataLastClm).Interior.Color = vbYellow
                End If
            End If
        End With
    Next Rw

    ' count flash
    Flashes = Flashes + 1
    'Calls the timer macro so it can be run again at the next interval.
    Call Timer

End Sub

The timer is stopped after MaxFlashes via:

Sub StopTimer()
    On Error Resume Next
    'stop flash due
    Application.OnTime earliesttime:=Interval, procedure:="Flash", schedule:=False

End Sub

which is also called when the workbook closes (to prevent any flash events hanging around).

Furthermore, There's data validation for the days (in column B) and Done? in column E (Y/N/blank)- if you change the latter to Y, the event macro will clear the highlight (if yellow, including during flashes) and record the time in column F. If you need to change it back to N, it will restore the yellow and clear that time.. That's done by this event macro (behind Sheet1):

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Rw As Range

    ' do nothing unless single cell in Done column is changed
    If Intersect(Target, Columns(DoneClm)) Is Nothing Or Target.CountLarge > 1 Then Exit Sub
    ' stop retriggering this event code
    Application.EnableEvents = False
    ' check value and if Y add time and clear fill
    If Cells(Target.Row, DoneClm) = "Y" Then
        Cells(Target.Row, DoneTimeClm) = Now
        Range(Cells(Target.Row, 1), Cells(Target.Row, DataLastClm)).Interior.ColorIndex = vbnone

        Else 'reapply colour
        Cells(Target.Row, DoneTimeClm) = ""
        Range(Cells(Target.Row, 1), Cells(Target.Row, DataLastClm)).Interior.Color = vbYellow
    End If
    Application.EnableEvents = True

End Sub

Hope this fixes things for you or gives you a good clue for your particular issue. If so, please be sure to mark this Answer as Selected.

Discuss

Discussion

Glad that seems to have worked for or helped you. Thanks for selecting my Answer, John
John_Ru (rep: 6142) Oct 14, '23 at 10:11 am
Hang on- seems you've now deselected it! Problem?
John_Ru (rep: 6142) Oct 14, '23 at 10:12 am
I'm sorry. WillieD24 Had given me the solution That I used. But I can't find any way to select his answer like yours. Don't get me wrong, you had a very fine, detailed answer. But in all fairness, WillieD had already solved my problem.
JohnThro60 (rep: 4) Oct 14, '23 at 5:44 pm
Understood. You can't "Select" a solution given in the discussion under a question- if Willie had made his points as an Answer instead, you could have selected it (and so enhanced his reputation). You could suggest that in your discussion under your question (he's involved in that so should get an Alert, but wouldn't in this thread). As it stands, neither Willie nor I get any (reputational) "reward" for our efforts. 
John_Ru (rep: 6142) Oct 14, '23 at 6:13 pm
Thank You John.
WillieD24 has reposted his discussion as an answer, so he was able to get credit. 
Thank you for your help as well. I am sure I will need another question answered someday, as my spreadsheet keeps track of my entire business.
JohnThro60 (rep: 4) Oct 14, '23 at 11:23 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login