Maybe...
This deletes the worksheet named summary and recreates it.
Option Explicit
Sub testme02()
Dim wks As Worksheet
Dim SumWks As Worksheet
Dim DestCell As Range
Dim myClasses As Variant
Dim HowManyClasses As Long
Dim myHourTypes As Variant
Dim HowManyHourTypes As Long
Dim HowManyRows As Long
Dim iCtr As Long
Dim myFormula As String
'remove the Summary worksheet
On Error Resume Next
Application.DisplayAlerts = False
Worksheets("Summary").Delete
Application.DisplayAlerts = True
On Error GoTo 0
myClasses = Array("GF", "F", "JW", "AP")
HowManyClasses = UBound(myClasses) - LBound(myClasses) + 1
myHourTypes = Array("ST", "OT", "DT")
HowManyHourTypes = UBound(myHourTypes) - LBound(myHourTypes) + 1
HowManyRows = HowManyClasses * HowManyHourTypes
Set SumWks = Worksheets.Add
With SumWks
.Name = "Summary"
.Range("A1").Resize(1, 5).Value _
= Array("WksName", "Date", "Key", "Hr Type", "hours")
Set DestCell = .Range("a2")
End With
For Each wks In ThisWorkbook.Worksheets
Select Case wks.Name
Case Is = SumWks.Name
'do nothing
Case Else
'put the worksheet name in column A
DestCell.Resize(HowManyRows, 1).Value = "'" & wks.Name
'put the date in column B
With DestCell.Offset(0, 1).Resize(HowManyRows, 1)
.Value = wks.Range("b6").Value
.NumberFormat = "mm/dd/yyyy"
End With
'put the formula to determine hours in column E
myFormula _
= "=SUMPRODUCT(--('" & wks.Name & "'!R9C3:R44C3=RC3)," _
& "--('" & wks.Name & "'!R9C5:R44C5=RC4)," _
& "'" & wks.Name & "'!R9C6:R44C6)"
myFormula = Replace(myFormula, "@", Chr(34))
DestCell.Offset(0, 4).Resize(HowManyRows, 1).FormulaR1C1 _
= myFormula
'put the key and hour types options in C
For iCtr = LBound(myHourTypes) To UBound(myHourTypes)
DestCell.Offset(0, 2).Resize(HowManyClasses, 1).Value _
= Application.Transpose(myClasses)
DestCell.Offset(0, 3).Resize(HowManyClasses, 1).Value _
= Application.Transpose(myHourTypes(iCtr))
Set DestCell = DestCell.Offset(HowManyClasses, 0)
Next iCtr
End Select
Next wks
End Sub
I like to know where the data comes from. I put the worksheet name in column
A. The date in column B. The class type in column C. The hour type in D and
the total hours in column E.
In R1C1 reference style, this: R9C3:R44C3
is row 9, column 3 through row 44, column 3
(C9:C44 in A1 reference style)
And RC3 means the same row column 3 (C### in A1 reference style)
After the data is laid out like this, you could use a pivottable to see nice
summaries.
Dave:
This is my original post (and the one I am looking for a macro for and how
to set up). Please let me know if you can help.
Dave: