+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    07-22-2009
    Location
    NYC, NY
    MS-Off Ver
    Excel 2003
    Posts
    22

    data on multiple rows

    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
    Attached Files Attached Files

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,493

    Re: data on multiple rows

    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
    Code:
    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
    Workbook Events Code
    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 Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0