Okay, so I have a spreadsheet that has a number of activities taking up time. The easiest way to describe this is through an example, so I have made an example as to how the spreadsheet is set up. (I'm going to assume you can look at it ... otherwise this question won't make a whole lot of sense).
Anyway, so I want the conditional format of the merged cell to change based on the time. If NOW() is between the two times, I want the fill of the merged cell to become green.
Unfortunately, I have no way of determining how long each activity is simply based on the cell. Because it is a merged cell, I'm finding it difficult to discover how many rows it occupies, even. So, I can figure it out if there's a way to determine how many rows a merged cell occupies, or another way I can't think of.
Any help it much appreciated. Thanks
Hello nesthead98,
This macro is based on your example using columns "A" and "B". The macro will start running when the workbook is opened and stop when the workbook is closed. There are 2 code portions. The main macro goes into a VBA module. The start and stop commands are placed in the Workbook event modules "Open" and "BeforeClose", respectively.
Main Macro Code
Workbook Events CodeCode:Private Sub ShowActivity() Dim Rng As Range Dim T As Variant Dim TimeCell As Range Dim Wks As Worksheet Set Wks = Worksheets("Sheet1") Set Rng = Wks.Range("A1", Wks.Cells(Rows.Count, "A").End(xlUp)) Rng.Offset(0, 1).Interior.ColorIndex = xlColorIndexNone T = Format(Now(), "hh:mm") Set TimeCell = Rng.Find(T, , xlValues, xlWhole, xlByRows, xlNext, False) If TimeCell Is Nothing Then Exit Sub Set Rng = TimeCell.Offset(0, 1) Rng.MergeArea.Interior.ColorIndex = 4 'Green Application.OnTime Now + TimeValue("00:01:00"), "ShowActivity" End Sub Sub TrackActivity(Enabled As Boolean) If Enabled Then Application.OnTime Now, "ShowActivity" Else On Error Resume Next Application.OnTime EarliestTime:=Now, Procedure:="ShowActivity", Schedule:=False End If End Sub
Code:Private Sub Workbook_BeforeClose(Cancel As Boolean) TrackActivity = False End Sub Private Sub Workbook_Open() TrackActivity True End Sub
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks