+ Reply to Thread
Results 1 to 9 of 9

Thread: Work out Time in and out based on Cell format

  1. #1
    Registered User
    Join Date
    11-22-2008
    Location
    Brisbane, Australia
    MS-Off Ver
    2003
    Posts
    23

    Work out Time in and out based on Cell format

    Hey guys, I have a sheet that I want to calculate what time a shift starts based on a cell shading.

    Basically Cells C6 and D6 need to be auto calculated based on the cells that are shaded from G6:L6

    Look at the Attachment and you will see what I mean.

    Thanks in advance.
    Attached Files Attached Files
    Last edited by merilvingian; 01-15-2009 at 05:26 AM.

  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,979
    Hello merilvingian,

    I see you have a macro (UDF) written aand are using in with worksheet IF statements. What do you want to do differently?

    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    11-22-2008
    Location
    Brisbane, Australia
    MS-Off Ver
    2003
    Posts
    23
    Hi Thanks for the reply,

    I would like the time to be worked out automatically. Not the hours worked, but when the line starts and finishes in each row. Each column represents half an hour.

    So when the line starts on G6 and finishes on L6 That would be 6am to 9am

    Thanks
    Steven

    Quote Originally Posted by Leith Ross View Post
    Hello merilvingian,

    I see you have a macro (UDF) written aand are using in with worksheet IF statements. What do you want to do differently?

    Sincerely,
    Leith Ross

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

    I just noticed your in Brisbane. Is that Brisbane, CA? Just to be sure I understand this, you want the time in columns "C" and "D" to be filled in when the cells in columns "G:L" are colored?

    Sincerely,
    Leith Ross

  5. #5
    Registered User
    Join Date
    11-22-2008
    Location
    Brisbane, Australia
    MS-Off Ver
    2003
    Posts
    23
    Hey, Nah Brisbane Australia, and yes thats exactly what I want it to do.

    Quote Originally Posted by Leith Ross View Post
    Hello Steven,

    I just noticed your in Brisbane. Is that Brisbane, CA? Just to be sure I understand this, you want the time in columns "C" and "D" to be filled in when the cells in columns "G:L" are colored?

    Sincerely,
    Leith Ross

  6. #6
    Registered User
    Join Date
    11-22-2008
    Location
    Brisbane, Australia
    MS-Off Ver
    2003
    Posts
    23
    Anyone had any luck yet?

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

    It times like these that make me think the universe (perhaps multiverse) just likes to mess with me. My wife comes home from work sick, my computer crashes twice and now the forum is running really slow. So, I am going to rewrite the code, keep my fingers crossed and not beg the question.

    Sincerely,
    Leith Ross

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

    Finally, it is done. Here is the macro that has been installed in the attached workbook. It updates the times once you move outside the "bars" table.
    Sub GetStartAndFinish(Target As Range)
    
      Dim C As Long
      Dim Cell As Range
      Dim FinishTime As Variant
      Dim R As Long
      Dim Rng As Range
      Dim StartTime As Variant
      
        Set Cell = Target.Cells(1, 1)
        Set Rng = Range("G6:M14")
        
          If Not Intersect(Cell, Rng) Is Nothing Then
            R = Cell.Row
            Set Rng = Range(Cells(R, "G"), Cells(R, "M"))
              For Each Cell In Rng
                If Cell.Interior.ColorIndex = 1 Then
                   If StartTime = 0 Then StartTime = Cell.Column
                   FinishTime = Cell.Column
                End If
              Next Cell
            
             If StartTime <> 0 And FinishTime <> 0 Then
                Cells(R, "C") = Cells(3, StartTime)
                Cells(R, "D") = Cells(3, FinishTime)
             Else
                Cells(R, "C") = ""
                Cells(R, "D") = ""
             End If
          End If
          
    End Sub
    Worksheet Selection Change Event Code
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      Application.EnableEvents = False
        GetStartAndFinish Target
      Application.EnableEvents = True
    End Sub
    Sincerely,
    Leith Ross
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    11-22-2008
    Location
    Brisbane, Australia
    MS-Off Ver
    2003
    Posts
    23
    WOW Thanks heaps. Awesome work.

    And sorry to hear that your wife is sick, I hope she gets better.

    Thank you so much.

    Best regards
    Steven

+ Reply to Thread

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