```
Sub SheetDataChart(Y As Long)
Dim ws1 As Worksheet, _
ws2 As Worksheet, _
wsm As Worksheet, _
p As String, _
NumLoops As Long, _
WeekSNum As Long, _
X As Long, _
DT As Date, _
DF As Date, _
Yearstart As Date
Set ws1 = Sheets("Sheet1")
Set ws2 = Sheets("Sheet2")
Set wsm = Sheets("Master")
ws1.Range("C5") = CDate(Sheets("Sheet1").txtDateFrom.Value)
ws1.Range("G5") = CDate(Sheets("Sheet1").txtDateTo.Value)
DF = (ws1.Range("C5") + 7) - (Weekday((ws1.Range("C5") + 7), 2))
DT = (ws1.Range("G5") + 7) - (Weekday((ws1.Range("G5") + 7), 2))
Yearstart = ws1.Range("H23")
With wsm
.Cells.Clear
End With
NumLoops = (DT - DF) / 7 + 1
''Sets the value for NumLoops based on 2 date values in sheet1
WeekSNum = (DF - Yearstart) / 7 + 1
''Sets the value for WeekSNum based on 2 values in sheet1
X = 0
''Sets the start value for X
Do Until X = NumLoops
p = "Week" & WeekSNum + X
On Error Resume Next
With Sheets(p).Range("A1:A200")
Set rng = .Find(ws2.Range("A" & Y))
rng1 = rng.Row
End With
If Sheets(p).Range("S3") = "Total" Then
Sheets(p).Range("C" & rng1, "Q" & rng1).Copy wsm.Range("C1").Offset(X, 0)
Sheets(p).Range("S" & rng1).Copy wsm.Range("AE1").Offset(X, 0)
ElseIf Sheets(p).Range("U3") = "Total" Then
Sheets(p).Range("C" & rng1, "S" & rng1).Copy wsm.Range("C1").Offset(X, 0)
Sheets(p).Range("U" & rng1).Copy wsm.Range("AE1").Offset(X, 0)
ElseIf Sheets(p).Range("W3") = "Total" Then
Sheets(p).Range("C" & rng1, "U" & rng1).Copy wsm.Range("C1").Offset(X, 0)
Sheets(p).Range("W" & rng1).Copy wsm.Range("AE1").Offset(X, 0)
ElseIf Sheets(p).Range("Y3") = "Total" Then
Sheets(p).Range("C" & rng1, "X" & rng1).Copy wsm.Range("C1").Offset(X, 0)
Sheets(p).Range("Y" & rng1).Copy wsm.Range("AE1").Offset(X, 0)
ElseIf Sheets(p).Range("AA3") = "Total" Then
Sheets(p).Range("C" & rng1, "Z" & rng1).Copy wsm.Range("C1").Offset(X, 0)
Sheets(p).Range("AA" & rng1).Copy wsm.Range("AE1").Offset(X, 0)
ElseIf Sheets(p).Range("AC3") = "Total" Then
Sheets(p).Range("C" & rng1, "AB" & rng1).Copy wsm.Range("C1").Offset(X, 0)
Sheets(p).Range("AC" & rng1).Copy wsm.Range("AE1").Offset(X, 0)
ElseIf Sheets(p).Range("AE3") = "Total" Then
Sheets(p).Range("C" & rng1, "AD" & rng1).Copy wsm.Range("C1").Offset(X, 0)
Sheets(p).Range("AE" & rng1).Copy wsm.Range("AE1").Offset(X, 0)
End If
wsm.Range("CZ1").Offset(X, 0) = p
X = X + 1
On Error GoTo 0
Loop
End Sub
```