Hi Mcrawiva
This Code has been modified to add Headers to Summary if they don't exist.
Mods and Admins...please excuse the absence of Code Tags...my current Interface lacks that Option
Option Explicit
Sub Create_Summary()
Dim ws As Worksheet, ws1 As Worksheet
Dim NR As Long, LR As Long, i As Long, j As Long
Dim myArray As Variant, Headers As Variant
Dim c As Range, cel As Range
myArray = Array("NUCLEAR Total", "COAL Total", "GAS Total", "HYDRO Total", "WIND Total", "OTHER Total")
Headers = Array("Date", "Nuclear", "Coal", "Gas", "Hydro", "Wind", "Other", "Total Energy Output for 24 hrs")
Set ws = Sheets("Summary")
Application.ScreenUpdating = False
With ws
.Cells.Clear
.Range("A3").Resize(1, UBound(Headers) + 1) = Headers
NR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row + 1
End With
j = 2
For Each ws1 In ThisWorkbook.Sheets
If ws1.Name <> "Summary" And Not ws1.Name = "Sheet1" Then
With ws1
' .Range("AA5").Value = "Total Energy Output for 24 hrs"
LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
.Range("H4").FormulaR1C1 = "=SUM(RC[-24]:RC[-1])"
.Range("H4").AutoFill Destination:=.Range("H4:H" & LR), Type:=xlFillDefault
' For Each cel In .Range("AA6:AA" & LR)
' cel.FormulaR1C1 = "=SUM(RC[-24]:RC[-1])"
' Next cel
End With
ws.Range("A" & NR).Value = ws1.Name
With ws1.Columns(1)
For i = LBound(myArray) To UBound(myArray)
Set c = .Find(myArray(i), LookIn:=xlValues)
ws.Cells(NR, j).Value = c.Offset(1, 26).Value
j = j + 1
Next i
End With
ws.Cells(NR, j - 1).Offset(0, 1).FormulaR1C1 = "=SUM(RC[-6]:RC[-1])"
j = 2
NR = NR + 1
End If
Next ws1
Application.ScreenUpdating = True
End Sub
Bookmarks