Little Help with formula for tracking days worked

mikeym

New Member
Joined
Jan 1, 2012
Messages
15
I need to track what days a person worked and the if they work 7 or more days in a row have it highlight those days ( say if I worked 9 days in row those cells would change to Red).
I will tracking this for a full year.

The formula I started using was =IF(ISNUMBER(MATCH("mike",C7:C18,0)),"Yes","No") Just could not figure out how to do the color change part.

Thanks for any help ..:)
 
Hey I had a request to change my book and make the Dates going top to bottom and names across top. Can this be changed to still work?
 
Upvote 0
[TABLE="class: grid, width: 200, align: center"]
<tbody>[TR]
[TD][/TD]
[TD]mike
[/TD]
[/TR]
[TR]
[TD]1-1-16
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1-2-16
[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Like this...just reverse what I had...(go figure)
 
Upvote 0
Code:
Sub highlightDays()


Dim myRow As Long, myCol As Long, myCount As Integer
Dim lastRow As Long, lastCol As Long


lastRow = Cells(Rows.Count, 1).End(xlUp).Row
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column


For myCol = 2 To lastCol
    myCount = 0
    For myRow = 2 To lastRow
        If Cells(myRow, myCol).Value = "Yes" Or Cells(myRow, myCol).Value = "yes" Then
            myCount = myCount + 1
        Else
            myCount = 0
        End If
        If myCount >= 7 Then
            Range(Cells(myRow - myCount + 1, myCol), Cells(myRow, myCol)).Interior.ColorIndex = 6
        End If
    Next myRow
Next myCol


End Sub
 
Last edited:
Upvote 0
Ok I was testing this and If I have say 14 "yes" If I replace a yes with a no It changes them all even if there is seven in a row still.
 
Upvote 0
My last post didn't include the "clear highlights" line. Try it like this:

Rich (BB code):
Sub highlightDays()


Dim myRow As Long, myCol As Long, myCount As Integer
Dim lastRow As Long, lastCol As Long


lastRow = Cells(Rows.Count, 1).End(xlUp).Row
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column

Range(Cells(1,1),Cells(lastRow,lastCol)).Interior.ColorIndex = 0 'this resets the highlights

For myCol = 2 To lastCol
    myCount = 0
    For myRow = 2 To lastRow
        If Cells(myRow, myCol).Value = "Yes" Or Cells(myRow, myCol).Value = "yes" Then
            myCount = myCount + 1
        Else
            myCount = 0
        End If
        If myCount >= 7 Then
            Range(Cells(myRow - myCount + 1, myCol), Cells(myRow, myCol)).Interior.ColorIndex = 6
        End If
    Next myRow
Next myCol


End Sub
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top