Method to highlight names with consecutive attendance

AlexCHI

New Member
Joined
Sep 28, 2017
Messages
19
I am using Excel 2007 and asking your help for the best (and the easiest) way to highlight the names of people who have 6-month of consecutive attendance every Sundays.

My worksheet's layout are as follow:
Column A: Last Name
Column B: First Name
Row 9: Dates (with "S9" as Jan 01, 2017 thru "NS9" as Dec 31, 2017)
Row 10: Days (with "S10" as Sunday thru "NS10" as Sunday)

The attendance is taken by marking an "X" in the Sunday columns (i.e., 1/01/2017, 1/08/2017, 1/15/2017 and so on). So whoever attends every Sunday for 6-month straight would have their names (last/first) in column A/B highlighted. I am not sure if conditional formatting can achieve this or VBA? I greatly appreciate your input and please kindly provide the steps to achieve this. Thank you in advance!
 
Hi Oldbrewer,

Thank you for your reply. In response to your question, I want every individual who ever had a 6-month consecutive Sunday attendance highlighted. Those who ever had a 6-month consecutive Sunday attendance will be qualified as a member and have their names highlighted to show eligibility. Any more (or less) attendance thereafter does not affect their membership. Also, the 6-month run can start any Sunday and not necessay to begin in January. Hope this clarifies things a bit. Thank you again.
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
[TABLE="width: 974"]
<colgroup><col><col span="2"><col span="12"></colgroup><tbody>[TR]
[TD][/TD]
[TD="align: right"]01/01/2017[/TD]
[TD="align: right"]08/01/2017[/TD]
[TD="align: right"]15/01/2017[/TD]
[TD="align: right"]22/01/2017[/TD]
[TD="align: right"]29/01/2017[/TD]
[TD="align: right"]05/02/2017[/TD]
[TD="align: right"]12/02/2017[/TD]
[TD="align: right"]19/02/2017[/TD]
[TD="align: right"]26/02/2017[/TD]
[TD="align: right"]05/03/2017[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]fred[/TD]
[TD]X[/TD]
[TD]X[/TD]
[TD][/TD]
[TD]X[/TD]
[TD]X[/TD]
[TD][/TD]
[TD]X[/TD]
[TD]X[/TD]
[TD][/TD]
[TD]X[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]bill[/TD]
[TD][/TD]
[TD]X[/TD]
[TD]X[/TD]
[TD]X[/TD]
[TD][/TD]
[TD]X[/TD]
[TD]X[/TD]
[TD]X[/TD]
[TD][/TD]
[TD]X[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="colspan: 8"]as before for testing purposes we are looking for any 3 consecutive attendances[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]scores[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]fred[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[TD]< < < L14[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]bill[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]1[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="colspan: 5"]THE HELPER ROWS find all runs of 3 or more[/TD]
[TD="colspan: 3"]fred has none of course[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="colspan: 5"]any total greater than zero makes a person a member[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="colspan: 7"]now we just use conditional formatting on the names in the top table[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="colspan: 4"]the formula applied to fred is =L14>0[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="colspan: 3"]copied with format painter to bill[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="colspan: 3"]bill is highlighted yellow[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Hi Mick,

Thank you SO much for the extent of work you had done to help me out. It worked perfectly on my worksheet now! One little bump though... I had changed this line "If c >= 26 Then Dn.Resize(, 2).Interior.Color = vbYellow" to "If c >= 26 Then Dn.Resize(, 2).Font.Bold = True" and the code (i.e., making or dis-making the font bold) doesn't run as smooth as the yellow highlighting. For instance, if I remove some "AM"s or "PM"s from a 26+ weeks consecutive attended name, then oddly the name stays bold even though the attendance is no longer 6-consecutive-month. Is there a reason for this?

Also, would you please show me the line of code that instead of yellow highlight, the names in column A and B would be bold and in blue color?

Lastly Mick, I know this is a lot to ask of you but I really want to learn the thought process behind each line of codes you compiled below. Is it at all possible if you can teach me what each line means?

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Rng As Range, Dn As Range, Ac1 As Long, Ac2 As Long, c As Long
Dim Lst As Long
Set Rng = Range(Range("A11"), Range("A" & Rows.Count).End(xlUp))

If Not Intersect(Target, Rng.Offset(, 19).Resize(, 365)) Is Nothing And Target.Count = 1 Then
Rng.Resize(, 2).Interior.Color = xlNone

For Each Dn In Rng
 c = 0
 For Ac1 = 0 To 196 Step 7
    For Ac2 = Ac1 To Ac1 + 182 Step 7
        If UCase(Dn.Offset(, Ac2 + 19)) = "AM" Or UCase(Dn.Offset(, Ac2 + 19)) = "PM" Or UCase(Dn.Offset(, Ac2 + 19)) = "AM & PM" Then
            c = c + 1
           If c >= 26 Then Dn.Resize(, 2).Interior.Color = vbYellow
        Else
            c = 0
            Exit For
        End If
    Next Ac2
  Next Ac1
Next Dn
End If
End Sub
 
Upvote 0
Try this :-
If it works I'll add some code comments.
NB:- For some reason the code becomes a bit slower when the "Font,Bold" is used.
Code:
Private [COLOR="Navy"]Sub[/COLOR] Worksheet_Change(ByVal Target [COLOR="Navy"]As[/COLOR] Range)
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, Ac1 [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ac2 [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Lst [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A11"), Range("A" & Rows.Count).End(xlUp))
Application.ScreenUpdating = False
[COLOR="Navy"]If[/COLOR] Not Intersect(Target, Rng.Offset(, 19).Resize(, 365)) [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
[COLOR="Navy"]With[/COLOR] Rng.Resize(, 2)
    .Interior.Color = xlNone
    .Font.Bold = False
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
 c = 0
 [COLOR="Navy"]For[/COLOR] Ac1 = 0 To 196 [COLOR="Navy"]Step[/COLOR] 7
    [COLOR="Navy"]For[/COLOR] Ac2 = Ac1 To Ac1 + 182 [COLOR="Navy"]Step[/COLOR] 7
        [COLOR="Navy"]If[/COLOR] UCase(Dn.Offset(, Ac2 + 19)) = "AM" Or UCase(Dn.Offset(, Ac2 + 19)) = "PM" Or UCase(Dn.Offset(, Ac2 + 19)) = "AM & PM" [COLOR="Navy"]Then[/COLOR]
            c = c + 1
           [COLOR="Navy"]If[/COLOR] c >= 26 [COLOR="Navy"]Then[/COLOR]
                [COLOR="Navy"]With[/COLOR] Dn.Resize(, 2)
                    .Interior.ColorIndex = 33
                    .Font.Bold = True
                [COLOR="Navy"]End[/COLOR] With
           
           [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]Else[/COLOR]
            c = 0
            [COLOR="Navy"]Exit[/COLOR] For
        [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]Next[/COLOR] Ac2
  [COLOR="Navy"]Next[/COLOR] Ac1
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] If
Application.ScreenUpdating = True
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Try this :-
If it works I'll add some code comments.
NB:- For some reason the code becomes a bit slower when the "Font,Bold" is used.

Hi Mick.

Your code works perfectly! Thank you so much again. Being a newbie in the world of excel VBA, I didn't imagine my worksheet could turn out so well with the help of so many on this forum. I really appreciate your willingness to explain to me your lines of coding. Before doing so though, I have another issue hoping you could lend a hand (if it's not too much of a trouble). If it's going to be rewriting everything then please discard my request since I am already content with how the worksheet is working now...

The current issue is besides from your code, I have two other worksheet_change codes running- to hide and show columns with the date(s) and days as inputted in cell B3 (for date) and cell B5 (for day). There is a compile error of "duplicate declaration in current scope" if I paste your code after the two other codes shown below. And in the fear of messing it up because of my lack of proficiency in excel VBA, what I did was I pasted your code as a worksheet_selectionchange code instead. It works but the highlighting of the names would not "refresh" unless a cell in the same row be selected whereas if the code is running as a worksheet_change then the highlighting "refreshes" as soon as the value of the cell is modified. Your thought?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim OneDate As Variant
  Dim InvalidDates As String
  
  If Not Intersect(Target, Range("B3")) Is Nothing Then
    Application.ScreenUpdating = False
    If IsEmpty(Range("B3").Value) Then
      Columns("T:NT").Hidden = False
    Else
      Columns("T:NT").Hidden = True
      For Each OneDate In Split(Replace(Range("B3").Value, ", ", ","), ",")
        If IsDate(OneDate) Then
          Columns("T").Offset(, CDate(OneDate) - Range("T9").Value).Hidden = False
        Else
          InvalidDates = InvalidDates & vbLf & OneDate
        End If
      Next OneDate
    End If
    Application.ScreenUpdating = True
    If Len(InvalidDates) > 0 Then MsgBox "Invalid Dates Entered:" & InvalidDates
  End If
  
  Dim sDay As String
  Dim rFound As Range
  Dim c As Long
  
  If Not Intersect(Target, Range("B5")) Is Nothing Then
    Application.ScreenUpdating = False
    sDay = Left(Range("B5").Value, 3)
    Columns("T:NT").Hidden = False
    If Len(sDay) > 0 Then
      Set rFound = Range("S10:NT10").Find(What:=sDay, After:=Range("S10"), LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False, SearchDirection:=xlNext, SearchFormat:=False)
      If Not rFound Is Nothing Then
        Columns("T:NT").Hidden = True
        For c = rFound.Column To Columns("NT").Column Step 7
          Columns(c).Hidden = False
        Next c
      End If
    End If
    Application.ScreenUpdating = True
  End If
End Sub
 
Upvote 0
I don't totally see what you code/s are trying to do except basically hide columns, but I don't see why you can't place them all in the same "Change_Event". NB:- You can't have a more than one of the same change events in the same sheet
As each separate code is initiated by the target cell being either a specific cell or specific range of cells, and none of those cells are an intersect of the others, then only one code at a time will run depending on your target cell.
I should give it a go see what happens. !!!!!
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,085
Members
453,021
Latest member
Justyna P

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