Sub Wadelair(): Dim AccumD(25), AccumE(25) As Single, AccumT(25) As Single
Dim r As Long, D As Range, S As String, m As Integer, n As Integer: n = 1
Dim h As Long, i As Long, j As Long, k As Long
r = Cells.Find("This").row: Set D = Range("D1:D" & r): h = 1
j = D.Find("Short").row + 1: k = D.Find("Total").row - 1
ProcessBlock:
If i > j Then Exit Sub
For i = j To k
If Cells(i, 1) = "WEEKDAY" Then
Weekdays:
For m = 6 To 11
h = InStr(1, Cells(i, m), "$")
If h Then
S = Cells(i, m)
Cells(i, m) = Mid(S, 1, h - 1) & _
Mid(S, h + 1, Len(S) - 1): End If
If Left(Cells(i, m), 1) = "+" Then _
S = Cells(i, m): Cells(i, m) = Right(S, Len(S) - 1)
AccumT(n) = AccumT(n) + Val(Cells(i, m))
AccumD(n) = AccumD(n) + Val(Cells(i, m)): n = n + 1
Next m
If n = 25 Then n = 1
If n = 7 Or n = 13 Or n = 19 Then
i = i + 1: GoTo Weekdays: End If: End If
If Cells(i, 1) = "WEEKEND" Then
Weekends:
For m = 6 To 11
h = InStr(1, Cells(i, m), "$")
If h Then
S = Cells(i, m)
Cells(i, m) = Mid(S, 1, h - 1) & _
Mid(S, h + 1, Len(S) - 1): End If
If Left(Cells(i, m), 1) = "+" Then _
S = Cells(i, m): Cells(i, m) = Right(S, Len(S) - 1)
AccumT(n) = AccumT(n) + Val(Cells(i, m))
AccumE(n) = AccumE(n) + Val(Cells(i, m)): n = n + 1
Next m
If n = 25 Then n = 1
If n = 7 Or n = 13 Or n = 19 Then
i = i + 1: GoTo Weekends: End If
End If
Next i: n = 1
PostWDs:
For m = 6 To 11
Cells(i, m) = AccumD(n): n = n + 1
Next m
If n = 19 Then n = 1
If n = 7 Or n = 13 Then
i = i + 1: GoTo PostWDs: End If: i = i + 1
PostWEs:
For m = 6 To 11
Cells(i, m) = AccumE(n): n = n + 1
Next m
If n = 19 Then n = 1
If n = 7 Or n = 13 Then
i = i + 1: GoTo PostWEs: End If
Erase AccumD: Erase AccumE
j = D.Find("Short", Range("D" & i)).row + 1
k = D.Find("Total", Range("D" & j)).row - 1
GoTo ProcessBlock
End Sub
Bookmarks