Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 626
- Office Version
- 365
- 2010
- Platform
- Windows
The following code finds all the Fridays within a date range and then will bold that date. Within my workbook I have 6 sheets with the tabs labeled sheet1(Chart), 2015, 2016...2019. My worksheet is layed out with the date is in column A on all the sheets labeled with a year, on sheet2 the date range starts in 'A2' with the value of 1/1/2015 all the way to 'A366' with the value of '12/31/2015'(1 additional cell is added for the years that contain leap years). The year will change to match the sheet tab name.
The problem I am having is when I start with spreadsheet tab '2015 it will work, the value of c holds the values of the cell dates. I am aware that c is declared as range and not a date. When the For Loop goes to the next sheet and activates it and the loop begins for that sheet, the value of c still loops but contains sheet 2015 values and not 2016.
I setup Watches with Expressions
ActiveSheet.Name, c, and I. Both ActiveSheet.Name and I work as expected, ActiveSheet.Name displays the next sheets name and I increments by 1 but the value of c is the problem. What am I doing wrong? Thank You
The problem I am having is when I start with spreadsheet tab '2015 it will work, the value of c holds the values of the cell dates. I am aware that c is declared as range and not a date. When the For Loop goes to the next sheet and activates it and the loop begins for that sheet, the value of c still loops but contains sheet 2015 values and not 2016.
I setup Watches with Expressions
ActiveSheet.Name, c, and I. Both ActiveSheet.Name and I work as expected, ActiveSheet.Name displays the next sheets name and I increments by 1 but the value of c is the problem. What am I doing wrong? Thank You
Code:
Option Explicit
Sub PullFridays1()
Dim dat As Range
Dim c As Range
Dim rw As Integer
Dim WS_Count As Integer
Dim I As Integer
Set dat = ActiveSheet.Range("A2:A367")
WS_Count = ActiveWorkbook.Worksheets.Count
For I = 2 To WS_Count
ThisWorkbook.Worksheets(I).Activate
For Each c In dat
If Weekday(c) = vbFriday Then
Debug.Print c.Value
c.Font.Bold = True
End If
Next c
Next I
End Sub