800 sheets - 4 Hours...
As per Kaper suggestions...Down to 8 seconds...
I don't see the need for Error delete code...Perhaps formula need to be adjusted to ensure no errors in formula...
can only see once a sample file is uploaded containing such errors...
Option Explicit
Sub AllSheets()
Dim ws As Worksheet, ch As Object, lr As Long, clr As Long
Dim ydata As Range, xdata As Range, cell As Range
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For Each ws In ThisWorkbook.Worksheets
With ws
' ! Formula Code...............................................
lr = .Cells(.Rows.Count, 1).End(xlUp).Row
.Range(.Cells(1, 2), .Cells(lr, 2)).AdvancedFilter xlFilterCopy, , .Range("Q1"), True
.Range("M2:M" & lr).formula = "=IF(L2-E2=L2 ,"""",IF(L2-E2=-E2,"""",L2-E2))"
clr = .Cells(Rows.Count, 17).End(xlUp).Row
.Range("R1") = "Average"
.Range("R2:R" & clr).formula = "=AVERAGEIFS($M$2:$M$" & lr & ",$B$2:$B$" & lr & ",Q2)"
' ! Chart Code......................................................
Set cell = .Range("N20") ' ! Start Position of Chart
Set ch = .ChartObjects.Add(Left:=cell.Left, Width:=400, Top:=cell.Top, Height:=250)
lr = .Cells(.Rows.Count, 17).End(xlUp).Row
Set xdata = .Range("Q2:Q" & lr): Set ydata = .Range("R2:R" & lr)
With ch.Chart
.ChartType = xlXYScatterLines
.SeriesCollection.NewSeries
With .SeriesCollection(1): .XValues = xdata: .Values = ydata: End With
With .ChartArea.Border: .Color = vbRed: .Weight = 3.25: End With
End With
End With
Next ws
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Bookmarks