I have a workbook with 50+ sheets. On all but the last of these sheets, A19:L30 is the range I'm concerned with. Within each row in this range, cell Kx is a job code, Lx is a sub-code for the given job, and Jx is the total hours worked in a specific time period that were charged to that specific job code/sub code combination.
On the last sheet, I have all possible job code/sub code combinations listed in three columns, following the same format as the data on the other sheets. Ax is grand total hours charged to a given code combination, Bx is the job code, and Cx is the work code. What I'm trying to do is loop through all sheets in the workbook and compare Kx and Lx in the sheet being searched with Ax and Bx, respectively, in the last sheet, and if the codes match then add that row's totals to the grand total on the last sheet.
What I have so far:
Sub GetAllJobCodes()
Dim ws As Worksheet
Dim x As Integer
Dim z As Integer
Dim NumOfTotals As Integer
NumOfTotals = (JobCodesSorted.Count * WorkCodes.Count) + 1
Dim Totals(500) As Double
Dim TotalsTemp As Double
For x = 1 To NumOfTotals - 1
Totals(x) = 0
Next
For x = 2 To 53
For Each ws In ActiveWorkbook.Worksheets
For z = 19 To 30
If ws.Cells(z, 11) = Sheets("Job Totals").Cells(x, 2) And ws.Cells(z, 12) = Sheets("Job Totals").Cells(x, 3) Then
TotalsTemp = CDbl(Row.Cells(z, 10))
Totals(x) = Totals(x) + TotalsTemp
End If
Next z
Next ws
Next x
For x = 2 To NumOfTotals
Sheets("Job Totals").Cells(x, 1) = Totals(x)
Next
End Sub
JobCodesSorted and WorkCodes are defined further upstream. Running this code assigns NumOfTotals a value of 71. I run this code, and all totals in the final sheet populate as zero. Change the last For loop to Debug.Print rather than print to cells, and all array values print as zeroes. Am I missing something? Any help is appreciated.